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?

- 41,293
- 91
- 306
- 570
-
1The parent which is **being** merged. https://github.com/ginatrapani/ThinkUp/pull/1974/files – hjpotter92 Aug 19 '14 at 13:26
-
1How do you know which parent that is? – Shamoon Aug 19 '14 at 17:13
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.
The phrase "Compared to the common ancestor of those two commits" is important for understanding the context in which the changes are being made.
When a merge commit happens in Git, the changes are calculated relative to the common ancestor of the two branches being merged. This common ancestor is the most recent commit that the two branches share.
Let's take a simplified example:
- You have a branch
A
where the latest commit isA1
. - You create a new branch
B
fromA
at commitA1
. You make changes and commit them asB1
. - Meanwhile,
A
also has changes committed asA2
.
Now, you want to merge B
into A
. The common ancestor here is A1
, the point where B
branched off. The changes brought in by B
(in commit B1
) are compared to this common ancestor (A1
), not the latest commit on A
(A2
).
In this case, the merge will be a three-way merge between A1
(common ancestor), A2
(latest commit on A
), and B1
(latest commit on B
). Git will try to apply the changes from A1
to B1
onto A2
. The commit stats (additions and deletions) are calculated relative to this common ancestor (A1
).
The phrase "Compared to the common ancestor of those two commits" emphasizes that the changes are not directly compared between the two branches at their latest commits, but rather from the point they diverged.

- 1,262,500
- 529
- 4,410
- 5,250
-
is there any way of identifying whether each commit is a merge commit or are there are mulitple parents to that commit in github API level – Kasun Siyambalapitiya Apr 17 '17 at 12:00
-
From `man git-merge` it says that `git-merge - Join two or more development histories together` which may lead to multiple parent commits ( more than 2) for a certain commit. in that case how the stats are calculated – Kasun Siyambalapitiya Apr 17 '17 at 12:33
-
can you please have a look on this question http://stackoverflow.com/questions/43452249/how-to-indentify-which-commit-introduce-which-changes-in-a-octopuss-merge/43453033#43453033 – Kasun Siyambalapitiya Apr 18 '17 at 03:12
-
1
-
@VonC, why add the words "*Compared to the common ancestor of those two commits*"? – Pacerier Jun 04 '23 at 23:12
-