如何使用git log --graph显示标签名称和分支名称

时间:2011-08-11 08:25:08

标签: git

我正在使用gitk --all来查看git日志。 gitk不会为每个提交显示sha哈希值。您需要手动单击提交以查看sha哈希。我想在单个视图中看到sha哈希和分支名称。

如何使用git log命令显示标记名称和分支名称。

2 个答案:

答案 0 :(得分:33)

使用git log(因此,不是gitk),您可以使用漂亮格式的装饰选项(%d)来显示分支名称(但仅适用于所述HEAD的提交)分支):

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

(你必须用:

声明该别名
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"

然后您可以将其与“git lgb”一起使用。注意:您可以使用其他别名命名。 )

会给:

* 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>

更新Git 2.2(2014年11月):请参阅commit 9271095中的Harry Jeffery (eXeC64)

pretty:添加%D格式说明符

  

添加新的格式说明符“%D”,其行为与“%d”相同,不同之处在于它不包含“(”前缀或“{{1 }''后缀由')'提供。

答案 1 :(得分:1)

我试过这个,它可以在我的电脑上运行

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' 

这将列出所有具有提交者名称的分支名称