Git Reachability and Merge Bases
Reachability is ancestry
A commit is reachable from a tip if following zero or more parent links can reach it. M reaches every labeled commit, including itself. C does not reach E. The common ancestors of C and E are A and B; B is the best one here because A is an ancestor of B. A merge base is not necessarily the most recent date, and criss-cross histories can have multiple best bases.
git merge-base --all C Egit rev-parse Bgit rev-list --count MUse exit status for ancestry
git merge-base --is-ancestor X Y has no ordinary output; status 0 means X is an ancestor of Y (including equality), status 1 means it is not, and other nonzero codes indicate errors. Check C M and E C below: the first is true, the second false. This proves ancestry within the available graph, not that a feature still exists in the final tree; a later revert can change content.
git merge-base --is-ancestor C Mprintf "exit=%s\n" "$?"git merge-base --is-ancestor E Cprintf "exit=%s\n" "$?"Shallow history is incomplete
Scenario B creates a depth-one clone using a local file URL and no tags. It has M but traversal treats it as a shallow boundary; rev-list --count HEAD reports 1 and HEAD^ cannot resolve. After fetching --unshallow from the fixture-owned complete origin, the count is 6 and HEAD^2 resolves to E. In CI, distinguish missing history from genuine unrelated history. Deepening requires authorized access to a suitable source.
git rev-parse --is-shallow-repositorygit rev-list --count HEADgit fetch --unshallow origingit rev-list --count HEADPractice: prove integration carefully
Ask whether D is reachable from M: yes, through M → E → D. Check it with --is-ancestor D M in the complete fixture. A branch name does not prove its contents were merged, and matching trees do not prove identical ancestry. Use graph checks and content checks together.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Reachability and Merge Bases — knowledge check
Predict revision resolution, commit sets and path selection.
What is the merge base of C and E?
What status means E is not an ancestor of C?
Is M reachable from M?
Why may a depth-one clone not resolve HEAD^?
Does ancestry alone prove that a fix is present in the current tree?