Git:找到两个分支的最近共同祖先
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1549146/
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: Find the most recent common ancestor of two branches
提问by Ted
How to find the most recent common ancestor of two Git branches?
如何找到两个 Git 分支的最近共同祖先?
回答by CB Bailey
You are looking for git merge-base
. Usage:
您正在寻找git merge-base
. 用法:
$ git merge-base branch2 branch3
050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
回答by Acumenus
As noted in a prior answer, git merge-base
works:
正如之前的回答中所指出的,git merge-base
有效:
$ git merge-base myfeature develop
050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
but if myfeature
is the current branch, as is common, you can use use --fork-point
:
但如果myfeature
是当前分支,这是常见的,您可以使用--fork-point
:
$ git merge-base --fork-point develop
050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
This argument works only in sufficiently recent versions of git. Unfortunately it doesn't always work, however, and it is not clear why. Please refer to the limitations noted toward the end of this answer.
这个论点只适用于足够新的 git 版本。不幸的是,它并不总是有效,然而,也不清楚为什么。请参阅本答案末尾指出的限制。
For full commit info, consider:
有关完整的提交信息,请考虑:
$ git log -1 $(git merge-base --fork-point develop)
回答by Martin G
With gitk
you can view the two branches graphically:
随着gitk
您可以图形方式查看两个分支:
gitk branch1 branch2
And then it's easy to find the common ancestor in the history of the two branches.
然后很容易在两个分支的历史中找到共同的祖先。