17

I am using gitk --all to view the git log. gitk does not display the sha hash for each commit. you need to manually click on the commit to view the sha hash. I want to see the sha hash and the branch name in a single view.

How to display the tag-names and branch names using the git log command.

Talespin_Kit
  • 17,730
  • 25
  • 86
  • 117
  • Note: if you need those branch names *without* parenthesis around, you now have the `%D` option (instead of `%d`), with Git 2.2 (Nov. 2014). See my edited answer below. – VonC Nov 29 '14 at 21:31

2 Answers2

39

With git log (so, not gitk), you can use the decorate option (%d) in a pretty format, for displaying the branch name (but only for commits which are the HEAD of said branches):

alias.lgb=log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches

(you have to declare that alias with:

git config --global alias.lgb "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches"

Then you can use it with 'git lgb'. Note: you can name it with a different alias. )

Will give:

* e33afe7 - (HEAD, master) fix zlib make install issue on cygwin (8 seconds ago) <VonC>
|
* f825f36 - add CPPFLAG option for cygwin compilation of gcc (26 hours ago) <VonC>
|
* 9341979 - (origin/master, origin/HEAD) update error messages for compiling gcc within cygwin (2 days ago) <VonC>
|
* 42d81af - copy dll in $H/usr/local/bin instead of linking when compiling in cygwin (3 days ago) <VonC>

Update Git 2.2 (November 2014): see commit 9271095 from Harry Jeffery (eXeC64):

pretty: add %D format specifier

Add a new format specifier, '%D' that is identical in behaviour to '%d', except that it does not include the ' (' prefix or ')' suffix provided by '%d'.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    I tried the command "git log alias.lgb=log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset%n' --abbrev-commit --date=relative --branches" which give s the error "fatal: ambiguous argument 'alias.lgb=log': unknown revision or path not in the w Use '--' to separate paths from revisions" – Talespin_Kit Aug 11 '11 at 09:04
  • @Talespin: I have added the correct `git config` command to declare that git alias. See also http://stackoverflow.com/questions/3666953/showing-git-branch-structure/3667139#3667139 or http://www.jukie.net/bart/blog/pimping-out-git-log – VonC Aug 11 '11 at 09:12
  • Thanks! added this to my dotfiles! https://github.com/chrisjlee/dotfiles/blob/master/.gitconfig – chrisjlee Oct 16 '15 at 17:13
  • @chrisjlee good idea :) I like to complement that `git lg` command with some bash aliases: https://github.com/VonC/b2d/blob/bb0a9afb4195da083e77157d54cb626d1b9eaa1d/git/bash_aliases#L4-L7 – VonC Oct 16 '15 at 17:41
  • 2
    This is my long time favorite alias, I can't up vote it enough. I also created a lg alias, dropping the --branches for when I only want to see the current branch... and lgbd with iso date instead of relative. Note that for this we need to change %Cgreen(%cr) to %Cgreen(%cd), otherwise the --date option is ignored. – scharette Nov 10 '18 at 14:00
2

I tried this and it works on my pc

git log --format='here you put formats you need for your case is like %d contain branch name and %cn committer  name ' | grep -F 'origin' 

this will list all branch names with committer names

Maxoizs
  • 105
  • 2
  • 4