I've got following history in git:
* 02e085a (master) readme update
| * 1d940da (HEAD -> b1) search.py
| | * 7aaa12d (b2) file2
| |/
| * 7be9db9 file1
|/
* 22601c0 initial commit
Now I'm on b2 and I would like to get the point, where b2 branched off (7be9db9). The algo is following:
However, if I want to do the same for b1, I end up at the same position - 7be9db9. But I would expect to end up at 22601c0, as this was the point, where b1 branched off. The history has been created like this.
initial commit branch from master (b1) and commit file1 branch from b1 (b2) and commit file2 checkout b1 and commit search.py
I'm afraid the way git is designed, it's not possible to distinguish, whether commit 7be9db9 (file1) has been created by b1 or b2, am I correct? So it's not possible to say, whether the parent of b1 is master or b2?
Thanks for confirmation.
I'm afraid the way git is designed, it's not possible to distinguish, whether commit 7be9db9 (file1) has been created by b1 or b2, am I correct? So it's not possible to say, whether the parent of b1 is master or b2?
Correct, it's impossible to know if b1 branched off b2, or b2 branched off of b1. When b2 branches off of b1 they point at the same commit and are topologically identical. The history of references is not stored.
If your process needs to know this, and I'm struggling to think why, choose another process.
What you can know is the common merge base between two branches with git-merge-base
. Typically this is the information you want. For example, a Github Pull Request knows what branch you want to merge into, and it can get all the commits to be merged with base..branch
.