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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7022890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:48:46  来源:igfitidea点击:

How to display the tag name and branch name using git log --graph

git

提问by Talespin_Kit

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.

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

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

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

回答by VonC

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):

使用git log(so, not 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

(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. )

然后您可以将它与“ git lgb”一起使用。注意:您可以使用不同的别名命名它。)

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 9271095from Harry Jeffery (eXeC64):

更新的Git 2.2(2014年11月):见犯9271095哈里杰弗里(eXeC64

pretty: add %Dformat specifier

pretty: 添加%D格式说明符

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'.

添加新的格式说明符“ %D”,它的行为与“ %d”相同,只是它不包括“ (”提供的“ ”前缀或“ )”后缀%d

回答by Maxoizs

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

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