GIT –pretty

18 / Feb / 2011 by Hitesh Bhatia 0 comments

git log is one of most useful commands to see information about commit , author , date and subject(comment)  while using GIT.This displays information in blocks and hardly 5 – 7 can be listed on normal screen size. But git provides –pretty option , so that we can format the output of git log;

Here are some ways to do that

git log --pretty=oneline

Displays just a single line log ,which includes a commit-hash and Subject(Comment).something like this

d1fc23c1edfd2d4ffe8ef5a873adff9321cde909 comment 3
a8560c814ece4e03d39164885f44e0c5cb749928 comment 2
db6195c635179b3556c41e2a974829c7e101ef51 comment 1

some other predefined options are raw,fuller,full,medium and short. Since Git is Cool we can also use some custom formats.Like

git log --pretty=format:"$h"

will give abbreviated hash of committs(Where %h defines abbreviated hash).And it would be something like

d1fc23c
a8560c8
db6195c

Which is not quite useful , to make it better lets first see other options

  • %H  – Commit hash
  • %s  – Subject
  • %h  – Abbreviated hash
  • %an – Author name
  • %ae – Author e-mail
  • %ad – Author date
  • %ar – Author date, relative



While using “format” with option “–pretty” we can also specify string inside quotes.Like

git log --pretty=format:"%h was committed by %an , %ar"

Would give something like

d1fc23c was committed by hiteshBhatia , 5 months ago a8560c8 was committed by hiteshBhatia , 5 months ago db6195c was committed by hiteshBhatia , 5 months ago

To make this more useful we can make slight changes to string passed to “format”

git log -3 --pretty=format:"%h ||  %an  ||   %s  (%ar)"

Which will give us commit hash , author name , subject  and relative date inside paranthesis.And -3 here is number of logs .So that his whole screen is not cluttered.This is the way I like to use it.

d1fc23c ||  hiteshBhatia  ||   comment 3  (5 months ago)
a8560c8 ||  hiteshBhatia  ||   comment 2  (5 months ago)
db6195c ||  hiteshBhatia  ||   comment 1  (5 months ago)



To explore more visit. git grep manual page or the git community book which is maintained by Scott Chacon

_________________________________
Hitesh Bhatia
Mail,LinkedIn,Facebook,Twitter
_________________________________
FOUND THIS USEFUL? SHARE IT

Leave a comment -