Git 日志图,显示两个分支如何分歧

问题描述 投票:0回答:4

我们想查看两个分支如何分歧的图表。运行

git log --oneline --graph
仅显示当前分支。我们如何在图中包含两个分支?

git
4个回答
84
投票

git log
采用零个或多个提交作为参数,显示导致该提交的历史记录。当没有给出参数时,假定为
HEAD
。对于您的情况,您需要提供您想要比较的两个分支负责人:

git log --graph --oneline currentbranch otherbranch

如果没有显示太多,您可以使用以下方法来简化

git log --graph --oneline --all

这就像您已将

.git/refs
中的每个引用指定为要显示的提交。


41
投票

我遇到了同样的问题并降落在这里,但没有答案帮助我显示两个分支如何分歧。最终我自己做了实验,发现这很有效。

给定分支

A
和分支
B
,我想看看它们在哪里分歧。

git log --oneline --graph --decorate A B `git merge-base A B`^!

注意:不要忘记最后有

^!
。 (它不包括
merge-base
返回的提交的父级。)

更新

如果合并基数超过一个,上面的一行命令将不起作用。在这种情况下,请执行以下操作:

git merge-base A B -a
# e.g. output XXXX YYYY
git log --oneline --graph --decorate A B --not XXXX^ YYYY^

0
投票

现在有一个更新的选项,虽然它不如@fikr4n的答案那么全面,但它提供了类似的信息。

git log --graph currentbranch...otherbranch

来自手册页:

Another special notation is "<commit1>...<commit2>" which is useful for merges. The 
resulting set of commits is the symmetric difference between the two operands. The
following two commands are equivalent:

     $ git log A B --not $(git merge-base --all A B)
     $ git log A...B

使用

--graph
很有帮助,因为它会将两个分支显示为两个断开连接的图。如果没有它,就不清楚提交属于哪个分支。


-2
投票
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
© www.soinside.com 2019 - 2024. All rights reserved.