如何查找先前的合并提交 [英] How to find previous merge commit

查看:75
本文介绍了如何查找先前的合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到两个分支之间的上一个合并提交?

How can one find the previous merge commit between two branches?

自上次将发行分支合并到master分支以来,我希望看到master分支中的更改.要查看发布分支自上一个分支以来的变化,它就像git diff ...release

I would like to see the changes in my master branch since the last time I have merged the release branch into the master branch. To see the changes in the release branch since the last branch, it is as easy as git diff ...release

但是显然git diff release...不起作用,因为它还包括最后一次合并之前的所有更改.因此,我认为我需要最后一次合并的提交ID才能将其传递给git diff

But obviously git diff release... doesn't work because it also includes all the changes before the last merge. Thus I think I need the commit id of the last merge to pass it to git diff

git log --reverse --ancestry-path `git merge-base HEAD release`.. \ 
        --format=format:%H|head -n1

似乎可以工作,并且可以与git diff $(...)一起使用,但是看起来非常复杂.有更简单的解决方案吗?

seems to work and can be used with git diff $(...), but it seems awfully complicated. Is there some easier solution?

示例

  I
 / \
A1 B1
 \ |
|  M   
|  |
A2 B2

此处I是初始提交. A[12]是版本提交,而B[12]是主提交. M是上一个提交.在该示例中,最后一次合并和主服务器之间的更改只是B2引入的更改. git merge-base A2 B2返回A 1.并且git diff B2 A1包括B1的更改.因此,问题是在更复杂的一般情况下如何查找M,以便人们可以运行git diff M B2而不必手动查找M.

Here I is the initial commit. A[12] are the release commits and B[12] are the master commits. M is the previous commit. In the example the changes between the last merge and master is just the changes introduces by B2. git merge-base A2 B2 returns A1. And git diff B2 A1 includes the changes of B1. Thus the question is how to find M in the general more complex case so that one can run git diff M B2 without having to manually find M.

推荐答案

您似乎正在寻找的是两个分支开始不同的点,而不是两个分支之间的最后合并.这两个概念是不同的,因为您的发布分支在合并后的某个时间可能已被快速转发.

It seems what you are looking for is the point at which the two branches started to differ, not the last merge between the two branches. These two concepts are different because your release branch may have been fast forwarded some time after it was merged.

git merge-base master release将找到master和release分支的最新共同祖先(即,两者共同的最后一次提交).

git merge-base master release will find the most recent common ancestor of your master and release branches (i.e. the last commit that the two have in common).

然后,在母版上,您可以使用git diff [common ancestor] HEAD查看自共同祖先以来对母版所做的更改.

Then, on master you can use git diff [common ancestor] HEAD to see the changes that have been made to master since the common ancestor.

这篇关于如何查找先前的合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆