git Git日志图,显示两个分支是如何发散的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26784396/
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
Git log graph, display how two branches are diverging
提问by Shaun Luttin
We would like to view a graph of how two branches are diverging. Running git log --oneline --graph
displays only the current branch. How do we include both branches in the graph?
我们想查看两个分支如何发散的图表。运行git log --oneline --graph
只显示当前分支。我们如何在图中包含两个分支?
回答by chepner
git log
takes zero or more commits as arguments, showing the history leading up to that commit. When no argument is given, HEAD
is assumed. For your case, you want to supply the two branch heads you want to compare:
git log
将零个或多个提交作为参数,显示导致该提交的历史记录。当没有给出参数时,HEAD
假设。对于您的情况,您希望提供要比较的两个分支负责人:
git log --graph --oneline currentbranch otherbranch
If it doesn't display too much, you can simplify this by using
如果它没有显示太多,您可以使用
git log --graph --oneline --all
which acts as if you had specified every reference in .git/refs
as the commits to display.
这就像您已将每个引用指定.git/refs
为要显示的提交一样。
回答by fikr4n
I had the same issue and landed here, but no answer helped me to display how two branches are diverging. Eventually I did experiment myself and found this worked.
我遇到了同样的问题并降落在这里,但没有答案帮助我显示两个分支是如何发散的。最终我自己做了实验,发现这很有效。
Given branch A
and branch B
, I want to see where they diverged.
鉴于 branchA
和 branch B
,我想看看他们分歧的地方。
git log --oneline --graph --decorate A B `git merge-base A B`^!
Note: Don't forget there is ^!
at the end. (It excludes the parents of the commit returned by merge-base
.)
注意:不要忘记^!
在最后。(它不包括由 返回的提交的父项merge-base
。)
UPDATE
更新
The one line command above isn't working in case merge base is more than one. In this case do this:
如果合并基数超过一个,则上面的一行命令不起作用。在这种情况下,请执行以下操作:
git merge-base A B -a
# e.g. output XXXX YYYY
git log --oneline --graph --decorate A B --not XXXX^ YYYY^
回答by Konrad Sza?wiński
git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all