I tried to get ancestor of my branch with git merge-base command on merged branch.
When I try git merge-base develop branch1 it shows sha YYY instead of XXX
* `develop`
|
* merge branch1 into develop
|\
| * `branch1` <- HEAD sha YYY
|/
* sha XXX
Everything works fine when I fire the same command on not merged branch (diagram bellow)
* `develop`
|
|
| * `branch1` <- HEAD sha YYY
|/
* sha XXX
The only way I get this commit id is by
git log --oneline --boundary develop...branch1
It shows me a list of commits but I need only one.
That's because the merge base after the merge is
YYY:is a vertical version of this same horizontal drawing:
The merge base of any two commits, such as
YandD, is the nearest commit reachable from both commits.Yreaches itself in zero steps;DreachesMand thenYin two steps; soYis a nearby common ancestor.While
Xis also a common ancestor, it is clearly more distant:YreachesXin one step, andDreachesXin two or three steps, eitherD-M-XorD-M-Y-X. SoD-to-Xis no further thanD-to-Y(min path is 2 steps either way), butY-to-Yis clearly shorter thanY-to-X.This means that
Yis the best common ancestor, and hence is the merge base.