views:

38

answers:

1

Hi

I am trying to find how to reference branch start commit from script. I mean the commit sha at which branch was forked.

Moreover I expect it work for history made from svn repo.

http://stackoverflow.com/questions/1006775/git-how-to-reference-the-initial-commit/1007545#1007545 just gives first commit of repo creation and not feature branch start commit.

Help :)

+4  A: 

What you're looking for is the command merge-base:

git merge-base master feature-branch

will print the best common ancestor of those two branches, i.e. where they forked apart. (The documentation has pretty pretty pictures to clarify some of the interesting cases)

Jefromi
Thanks. It's definitely what I need!
MageSlayer
Note that if you've merged between your branch and the trunk at any point, a parent of that merge will be returned rather than the 'original' branch point. I'm not sure you'll get any better answer, though.
Andrew Aylett
@Andrew: It depends on the exact use, but generally that's what you want, anyway, not the original one. If you do really want the original one, you can use the `-a/--all` option and take the first one instead of the last one.
Jefromi