简体   繁体   English

git 日志以图形方式显示 2 个分支上的所有提交,但仅显示最近的共享提交

[英]git log to graphically show all commits on 2 branches, but only show most recent shared commit

I have 2 branches in git which have diverged a little.我在 git 中有 2 个分支,它们有些不同。 I want to display the commits on both.我想显示两者的提交。 with git log --oneline --graph --decorate branch1 branch2 I can see the 2 branches, their history (graphically), and where they diverge.使用git log --oneline --graph --decorate branch1 branch2我可以看到 2 个分支、它们的历史(以图形方式)以及它们分歧的地方。 But this display shows all commits.但是这个显示显示了所有的提交。

How can I do the above command, but stop at the first commit these 2 branches have in common?我该如何执行上述命令,但在第一次提交时停止这两个分支的共同点? ie I want the last line of the output to be the commit which they have in common, and then see (in the graphical ASCII art way that git log --graph shows) the branches diverging.即我希望 output 的最后一行成为它们共同的提交,然后查看(以git log --graph显示的图形 ASCII 艺术方式)分支发散。

git version 2.17.1 on Ubuntu Linux 18.04 git 版本 2.17.1 上 Ubuntu Linux 18.04

git log --oneline --graph --decorate branch1...branch2 --boundary

branch1...branch2 refer to the commits that come after the nearest common commit (excluding the common commit). branch1...branch2指的是最近的公共提交之后的提交(不包括公共提交)。 --boundary prints the nearest common commit (the boundary commit) with o instead of * . --boundary使用o而不是*打印最近的公共提交(边界提交)。

Or或者

git log --oneline --graph --decorate branch1 branch2 ^$(git merge-base branch1 branch2)^

$(git merge-base branch1 branch2) refers to the nearest common commit. $(git merge-base branch1 branch2)指的是最近的公共提交。 C^ refers to the first parent of C . C^指的是C的第一个父级。 ^C means to exclude all the commits that come before C including C itself. ^C表示排除C之前的所有提交,包括C本身。 ^C^ means to exclude all the commits that come before C^ including C^ itself. ^C^表示排除C^之前的所有提交,包括C^本身。

The 1st command is suggested.建议使用第一个命令。 When the common commit is a merge commit, we need to exclude its other parent commit(s), with ^$(git merge-base branch1 branch2)^2 , ^$(git merge-base branch1 branch2)^3 , and so on.当公共提交是合并提交时,我们需要排除它的其他父提交,用^$(git merge-base branch1 branch2)^2^$(git merge-base branch1 branch2)^3等等上。 Or with a much long command to exclude all the ancestors of the common commit.或者使用很长的命令来排除共同提交的所有祖先。

git log --oneline --graph --decorate branch1 branch2 ^$(echo $(git log -1 --pretty=%P $(git merge-base branch1 branch2)) | sed -e 's/ / ^/g')

After searching the doc , the above command could be shortened to搜索文档后,上面的命令可以缩短为

git log --oneline --graph --decorate branch1 branch2 ^$(git merge-base branch1 branch2)^@

C^@ refers to all the parents of C. C^@指的是 C 的所有父母。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM