How a Git Merge Commit Connects Histories

A two-parent merge commit records a result reached by integrating two lines of development and preserves both tips as parents.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a divergence
  2. Read a history view carefully
  3. Read shared ancestry and distinct parents
  4. Check the resulting behavior even if merge is automatic

Trace a divergence

A common commit A is followed by B on one branch and C on another. A merge result M can have parents B and C. Its snapshot may contain edits from both. A commit as snapshot explains what result is recorded.

Read a history view carefully

The first parent commonly follows the branch receiving the merge. Comparing M with that parent shows the result brought into that line. A fast-forward is the simpler case where histories already form one ancestry line.[1]

Read shared ancestry and distinct parents

If branches at B and C both descend from A and a merge produces M, M can have B and C as parents. The resulting tree represents the resolved content. Looking only at the relationship to B gives one view of what the merge introduced. See snapshot and parent identities.

Common base A
Left tip B with parent A
Right tip C with parent A
Merge M parents B and C

Check the resulting behavior even if merge is automatic

Independent line edits can combine into a broken program without textual conflict. Test the combined result, then inspect comparisons with either parent when understanding the integration. Use parent order explicitly when following a particular history view.

References

  1. Scott Chacon and Ben Straub, Pro Git ↩