3

Suppose a git repo has two branches, master and test. commitA is made on the test branch. I want to check:

  1. Whether commitA has been merged to the master branch?
  2. If so, what is the SHA of the merge commit?

I want to check these programmatically (not by using gitk).

Ida
  • 2,919
  • 3
  • 32
  • 40
  • 2
    `git merge-base --is-ancestor` for the first. No easy answer I know of for the second without scripting. – Andrew C Dec 02 '14 at 05:06
  • Seems to be a duplicate of https://stackoverflow.com/questions/28180247/how-do-i-see-a-commits-path-through-git-history-or-how-it-got-in-the-current/28305568#28305568 actually. – Matthieu Moy Oct 02 '17 at 18:03

2 Answers2

0

There's a tool called git-when-merged that was designed exactly for this use-case. After installing it,

git when-merged commitA master

should do the trick.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
-1

By your example, the branch test is now at commit commitA. So you can check where commitA has been merged into master by this command:

git branch --contains test

This should list all branches that contains commitA, check to see if master is in the list.

For getting the SHA of commitA type:

git rev-parse test

The SHA of the merge commit and the commitA itself are the same.

Ryan Le
  • 1,357
  • 12
  • 7