I have a repository with branches master and A and lots of merge activity between the two. How can I find the commit in my repository when branch A was created based on master?
My repository basically looks like this:
-- X -- A -- B -- C -- D -- F (master)
\ / \ /
\ / \ /
G -- H -- I -- J (branch A)
I'm looking for revision A, which is not what git merge-base (--all)
finds.
The following implements git equivalent of svn log --stop-on-copy and can also be used to find branch origin.
Approach
Like all rivers run to the sea, all branches run to master and therefore we find merge-base between seemingly unrelated branches. As we walk back from branch head through ancestors, we can stop at the first potential merge base since in theory it should be origin point of this branch.
Notes
details: https://stackoverflow.com/a/35353202/9950
You may be looking for
git merge-base
:I've used
git rev-list
for this sort of thing. For example, (note the 3 dots)will spit out the branch point. Now, it's not perfect; since you've merged master into branch A a couple of times, that'll split out a couple possible branch points (basically, the original branch point and then each point at which you merged master into branch A). However, it should at least narrow down the possibilities.
I've added that command to my aliases in
~/.gitconfig
as:so I can call it as: