git commit 的父级是什么?一个 git 提交怎么可能有多个父级?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38239521/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:05:55  来源:igfitidea点击:

What is the parent of a git commit? How can there be more than one parent to a git commit?

git

提问by Rat Salad

I was looking at thisquestion when I got really confused. My understanding was that the previous commit is the parent of a commit.

当我真的很困惑时,我正在看这个问题。我的理解是之前的提交是提交的父级。

回答by Madara's Ghost

The parent commit is the commit this current commit is based on. Usually:

父提交是当前提交所基于的提交。通常:

  • When you git commitnormally, the current commit becomes the parent commit of the new commit that's introduced by the command.
  • When you git mergetwo commits (or branches, whatever) without fast-forwarding, a new commit will be created with bothcommits as parents. You can merge more than two commits in that way, so the new commit may have more than one parent.
  • 当你git commit正常,目前的承诺变为父提交新的承诺是年代由命令介绍。
  • 当您git merge在没有快进的情况下进行两次提交(或分支等)时,将创建一个新的提交,并将两个提交作为父提交。您可以通过这种方式合并两个以上的提交,因此新提交可能有多个父提交。

Essentially, the commit tree (or DAG, if we want to be accurate) is made up of those parent<-child relationships, with the children (more "recent"[1]commits) point to the parents (less "recent"[1]commits).

从本质上讲,提交树(或DAG,如果我们要准确)是由那些父<柴尔德的关系了,与孩子们(更“近” [1]提交)点给父母(少“近期” [ 1]提交)。

The only exception is the initial commit (or any other root commits), which has no parents.

唯一的例外是初始提交(或任何其他根提交),它没有父提交。



  1. "recent" isn't exactly an accurate term, as you may have a very old branch on the one hand, and a very new one on the other. And a child commit may be a lot "older" than another commit which is a parent elsewhere.
  1. “最近”并不完全是一个准确的术语,因为一方面您可能有一个非常旧的分支,另一方面是一个非常新的分支。并且子提交可能比其他地方的父提交“老”很多。