Where did I branch from?
There's no canonical answer for this, since branches are simply pointers to certain commits in a DAG. For instance, master
and foo
could be pointing at the same commit; if you then create a branch from foo
, it's effectively the same as creating a branch from master
.
That said, if you visualize the commit graph (via gitk
or some other graphical history tool), you can get a general sense of where the branch points are in the commit graph, versus where various branch pointers are pointing.
git merge-base shows the commit that is the common ancestor of two branches.
Simple usage: git merge-base <branch> <branch>
shows the common commit of the two branches.
If you are already on a branch then you can get the commit that is the point where it forked from another branch, say master
, like this:
git merge-base --fork-point master
Then fetch the commit message with git show <commit-id>
.
If you got no commit ids then this branch did not come from that.
For example I'm not sure if I forked from dev
or master
:
$ git checkout my-branch
$ git merge-base --fork-point master
$ git merge-base --fork-point dev
1770f75fa178df89a40ddc5f13ecd6bc597c17df
$ git show 1770f75fa178df89a40ddc5f13ecd6bc597c17df
commit 1770f75fa178df89a40ddc5f13ecd6bc597c17df (origin/popup-stack-12, dev)
Merge: 37f79cf f8a9795
Author: Superman <[email protected]>
Date: Sun Mar 29 23:14:40 2020 +0000
...
I forked this branch from dev.