Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a git commit has multiple parents, what are the stats calculated against?

Tags:

git

When a commit has multiple parents, like this one, we see that it has 4 additions and 4 deletions. My question is compared to what? Are the additions and deletions compared to the file as it existed in BOTH parents? Or how exactly is it compared?

like image 919
Shamoon Avatar asked Aug 19 '14 13:08

Shamoon


People also ask

Can a git commit have multiple parents?

Commits in git can have multiple parents, aka 'merge commits'. Using them maintains the branch history. They don't maintain the branch name, or even the history of the branch: they just tell what are the parent commits of the commit; as mentioned above, this history can be a "lie".

How many parent commits Can a git commit have?

When you git merge two commits (or branches, whatever) without fast-forwarding, a new commit will be created with both commits as parents. You can merge more than two commits in that way, so the new commit may have more than one parent.

How many parents can a commit have?

A git commit can have an arbitrary number of parents. This can be the case, for example, when you use git merge to merge more than one commit into your current branch.


1 Answers

It is a three-way merge between:

  • the common ancestor of both parents (git merge-base @^1 @^2, ^1 being the first parent, ^2 being the second parent of HEAD: see "Ancestry Reference".)
  • the second parent (commit c0ce149) acting as source (being merge to)
  • the first parent (commit 0994e7c) acting as destination (being on the branch where the merge occurs)
  • with HEAD (commit 4cd713e) being the result of the merge.

(you can see another example of three-way merge in this answer)

By convention, GitHub will always display the parents as:

  • The first parent, which is the branch you were on when you merged,
  • and the second parent, which is the commit on the branch that you merged in.

Compared to the common ancestor of those two commits, the second one, when merged into the first one, brings 4 additions and 4 deletions.

like image 139
VonC Avatar answered Nov 15 '22 16:11

VonC