Warm-up · from “Stash, shelving and worktrees”
What is the second parent of a normal stash commit?
What is the second parent of a normal stash commit?
No notes: write what you remember, then check. Recalling before reading is what makes it stick.
The problem
Two developers complete separate features. How does Git combine them without losing either person's changes?
After this lesson you can
Identify fast-forward and divergent histories.
Locate a merge base.
Explain the resulting parent links.
Key terms
Full glossarySay what each term means, then open it to check.
Merge base · new in this lesson
Best common ancestor of commits; there may be several.
Index · from lesson 9
Prepared path-to-object entries, plus metadata and conflict stages.
Commit · from lesson 7
Object identifying a root tree, parent(s), metadata and message.
Tree · from lesson 6
Directory snapshot mapping names, modes and object IDs.
Visual mental model
- Base A
- Ours: Bmain
- Theirs: Cfeature
- Merge Mtwo parents
Build the mental model
If the current tip is an ancestor of the incoming tip, a normal merge can fast-forward: move the current branch to the incoming commit and update the Index and working tree. No new commit is needed. If the incoming tip is already an ancestor, there is nothing to integrate. --no-ff can request a merge commit even when fast-forward is possible; --ff-only refuses divergence.
A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.
Under the hood
For diverged histories, Git finds a best common ancestor (there may be multiple) and compares the base, ours and theirs. Changes on only one side generally carry forward; independent edits may combine automatically. Conflicting edits require a resolution. The default ort strategy handles details such as renames and multiple merge bases. A successful ordinary divergent merge produces a commit with both tips as parents.
Common mistake · important nuance
A merge is not a blind overlay of one folder onto another. The base helps distinguish additions from deletions.