简体   繁体   English

如何获得合并分支分支的提交

[英]How to get commit where merged branch forked from

o---1---o---o---o---o     master
     \         /
      o---o---2           feature

Is it possible to get commit 1 without using reflog ?是否可以在不使用 reflog 的情况下获得 commit 1? Using git 2.4.2使用 git 2.4.2

I tried:我试过:

git merge-base master feature
git merge-base feature master
returns: commit 2 
git merge-base --fork-point master feature
git merge-base --fork-point feature master
returns nothing ( exit code 1 )

Not duplicates:不重复:

Found my answer as a subset from this question: ( backporting was in fact also my usecase ! ) https://stackoverflow.com/a/16718891/867294发现我的答案是这个问题的一个子集:(反向移植实际上也是我的用例!) https://stackoverflow.com/a/16718891/867294

[alias]
    oldest-ancestor = !bash -c 'diff -u <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | sed -ne \"s/^ //p\" | head -1' -

I am somewhat baffled that this is not part of git as default.我有点困惑,这不是 git 默认的一部分。 You would at least expect that this would be the behavior of the --fork-point option for merge-base .您至少会期望这将是merge-base--fork-point选项的行为。 If anyone knows a better/default alternative.如果有人知道更好/默认的替代方案。 Please put it in the comments or as a separate answer !请把它放在评论中或作为单独的答案!

As you noticed, git merge-base will not help you.正如您所注意到的, git merge-base不会帮助您。 The reason for this is that feature is part of master 's history and it could be fast-forwarded to master .这样做的原因是该featuremaster历史的一部分,它可以快进到master

If this is your specific setup though, that you have merged feature into master , and the feature branch still points to the commit before the merge, then you can just get all the commits that are included in master but not included in feature and take the last one;如果这是您的特定设置,您已将feature合并到master ,并且feature分支仍指向合并前的提交,那么您只需获取包含在master但未包含feature所有提交并获取最后一个; the merge base you are looking for is its parent.您正在寻找的合并基础是它的父级。 You can do that by specifying the range feature..master :您可以通过指定范围feature..master来做到这一点:

git show $(git rev-list feature..master | tail -1)~1

This will show you the merge base commit “1” in your graph.这将在您的图表中显示合并基础提交“1”。

我认为以下内容可以满足您的要求:

git merge-base --fork-point master

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

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