[英]git log to graphically show all commits on 2 branches, but only show most recent shared commit
我在 git 中有 2 个分支,它们有些不同。 我想显示两者的提交。 使用git log --oneline --graph --decorate branch1 branch2
我可以看到 2 个分支、它们的历史(以图形方式)以及它们分歧的地方。 但是这个显示显示了所有的提交。
我该如何执行上述命令,但在第一次提交时停止这两个分支的共同点? 即我希望 output 的最后一行成为它们共同的提交,然后查看(以git log --graph
显示的图形 ASCII 艺术方式)分支发散。
git 版本 2.17.1 上 Ubuntu Linux 18.04
git log --oneline --graph --decorate branch1...branch2 --boundary
branch1...branch2
指的是最近的公共提交之后的提交(不包括公共提交)。 --boundary
使用o
而不是*
打印最近的公共提交(边界提交)。
或者
git log --oneline --graph --decorate branch1 branch2 ^$(git merge-base branch1 branch2)^
$(git merge-base branch1 branch2)
指的是最近的公共提交。 C^
指的是C
的第一个父级。 ^C
表示排除C
之前的所有提交,包括C
本身。 ^C^
表示排除C^
之前的所有提交,包括C^
本身。
建议使用第一个命令。 当公共提交是合并提交时,我们需要排除它的其他父提交,用^$(git merge-base branch1 branch2)^2
, ^$(git merge-base branch1 branch2)^3
等等上。 或者使用很长的命令来排除共同提交的所有祖先。
git log --oneline --graph --decorate branch1 branch2 ^$(echo $(git log -1 --pretty=%P $(git merge-base branch1 branch2)) | sed -e 's/ / ^/g')
搜索文档后,上面的命令可以缩短为
git log --oneline --graph --decorate branch1 branch2 ^$(git merge-base branch1 branch2)^@
C^@
指的是 C 的所有父母。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.