Git - git-log Documentation --ancestry-path[=<commit>] https://git-scm.com/docs/git-log#Documentation/git-log.txt---ancestry-pathltcommitgt-1 The graph for `--ancestry-path=H D..M` should contain commit C. Code: mkdir --parents -- './repo' cd './repo' git init branch_default_name="$(git branch --show-current)"; echo "$branch_default_name" git commit --message='a' --allow-empty git checkout -b branch1 git commit --message='b' --allow-empty git checkout -b branch2 git commit --message='d' --allow-empty git commit --message='e' --allow-empty git checkout branch1 git commit --message='c' --allow-empty git merge --message='g' branch2 git checkout branch2 git commit --message='f' --allow-empty git checkout branch1 git commit --message='h' --allow-empty git merge --message='i' branch2 git commit --message='j' --allow-empty git checkout "$branch_default_name" git commit --message='k' --allow-empty git merge --message='l' branch1 git commit --message='m' --allow-empty git log --graph git log --graph --ancestry-path=:/'h' :/'d'..:/'m' Output: * 9e6572c - 2025-03-14 09:54 (1 second ago) m (HEAD -> refs/heads/master) * 9598130 - 2025-03-14 09:54 (2 seconds ago) l |\ | * 3579336 - 2025-03-14 09:54 (5 seconds ago) j (refs/heads/branch1) | * a144397 - 2025-03-14 09:54 (5 seconds ago) i | |\ | | * 721743e - 2025-03-14 09:54 (8 seconds ago) f (refs/heads/branch2) | * | ceaf310 - 2025-03-14 09:54 (6 seconds ago) h | * | 30e22bb - 2025-03-14 09:54 (9 seconds ago) g | |\| | | * 0f44e94 - 2025-03-14 09:54 (12 seconds ago) e | | * edecedf - 2025-03-14 09:54 (13 seconds ago) d | * | b4c952f - 2025-03-14 09:54 (10 seconds ago) c | |/ | * 11851d5 - 2025-03-14 09:54 (14 seconds ago) b * | 70c1b91 - 2025-03-14 09:54 (3 seconds ago) k |/ * 029edb2 - 2025-03-14 09:54 (16 seconds ago) a * 9e6572c - 2025-03-14 09:54 (1 second ago) m (HEAD -> refs/heads/master) * 9598130 - 2025-03-14 09:54 (2 seconds ago) l * 3579336 - 2025-03-14 09:54 (5 seconds ago) j (refs/heads/branch1) * a144397 - 2025-03-14 09:54 (5 seconds ago) i * ceaf310 - 2025-03-14 09:54 (6 seconds ago) h * 30e22bb - 2025-03-14 09:54 (9 seconds ago) g |\ | * 0f44e94 - 2025-03-14 09:54 (12 seconds ago) e * b4c952f - 2025-03-14 09:54 (10 seconds ago) c