2

I'm looking for a git command (or set of commands) that can return the 'branching' commit from the merge commit.

For example, suppose I have the following tree:

A______B______C_______D________E________F
        \_________G___________/

Given the merge commit E, the command should return B.

Abdelhakim
  • 815
  • 1
  • 5
  • 19

1 Answers1

3

The command you're looking for is git merge-base, it tells you what the most recent common ancestor there is for two commits.

To get the common ancestor for your E commit in your example, you would execute this command:

git merge-base E^1 E^2

where E would be whatever references the commit in question, like:

  • HEAD if you've currently checked out that commit
  • A branch name
  • A tag name
  • The hash of that commit
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825