如何确定哪个父级是Git中合并提交的第一个父级 [英] How to determine which parent is the first one for a merge commit in Git

查看:360
本文介绍了如何确定哪个父级是Git中合并提交的第一个父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读在git中使用~^运算符的区别,并且遇到了这个问题什么是Git中的HEAD ^和HEAD〜之间有什么区别?

I was reading about the difference in using a ~ vs ^ operator in git and I came across this question What's the difference between HEAD^ and HEAD~ in Git?

在谷歌搜索后我无法在网上找到很好的解释的一件事是git如何区分合并提交的第一个父级和第二个提交的父级?

The one thing I could not find a good explanation for online after googling is how does git distinguish the first parent of a merge commit from the second one?

有经验吗?

以本示例为例,其中将feature分支合并到 develop分支中,创建合并提交G.

Take this example where a feature branch is merged into the develop branch, creating the merge commit G.

develop feature/foo
     A   D
     |   |
     B   E
     |   |
     C   F
      \ /
       G <- develop(HEAD)

G的第一个父母是谁? CF?为什么是第一个父母?

Which one is the first parent of G? C or F? Why is it the first parent?

注意:这不是要求git命令确定第一个或第二个父对象.我知道可以使用git show G^1git show G^2来实现.我看到CG的第一个父级,而F是第二个父级.但是,我不明白为什么会这样.就像进行合并提交的分支确定第一个父级一样吗?

NOTE: This is not a request for the git command to determine the first or the second parent. I'm aware that it can be achieved using git show G^1 and git show G^2. I see that C is the first parent of G and F is the second parent. But, I do not understand why that is the case. Is it like the branch on which the merge commit is made determines the first parent?

推荐答案

就像执行合并提交的分支确定 第一父母?

Is it like the branch on which the merge commit is made determines the first parent?

是的

请参考 Git-Tools-Revision-Selection Pro Git:

Referring to Git-Tools-Revision-Selection of Pro Git :

您也可以在^后面指定一个数字,以标识您是哪个父母 想;例如,d921970 ^ 2表示"d921970的第二个父代". 此语法仅对具有多个合并合并的提交有用 parent-merge合并提交的第一个父项来自您的分支 合并时(通常是主节点)处于开启状态,而第二个父级处于开启状态 合并提交的内容来自已合并的分支(例如,主题):

You can also specify a number after the ^ to identify which parent you want; for example, d921970^2 means "the second parent of d921970." This syntax is useful only for merge commits, which have more than one parent — the first parent of a merge commit is from the branch you were on when you merged (frequently master), while the second parent of a merge commit is from the branch that was merged (say, topic):

git show G^1git show G^2git log -1 --pretty=%P Ggit rev-parse G^@之类的命令可以证明它与所描述的相同.此外,使用git cat-file -p G检查提交对象的内容,我们可以看到父对象已按顺序记录.

And commands like git show G^1, git show G^2, git log -1 --pretty=%P G, and git rev-parse G^@, can prove it's the same as described. Besides, use git cat-file -p G to inspect the content of the commit object, and we can see the parents are recorded in the order.

这篇关于如何确定哪个父级是Git中合并提交的第一个父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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