4

With the following git history:

            f---g---h--- feature
           /         \
      c---e---i---j---k---l--- release
     /                     \
-a--b---d---m---n---o---p---q---[hundreds of commits]--- master

I have the SHA of commit g. Neither feature, nor release are available any longer and I need to find commit q, IE where the release branch was merged into master. With the answers in a different question (Find merge commit which include a specific commit) I can only find commit k, where the feature branch was merged into the release branch. How do I go about this?

Community
  • 1
  • 1
antonagestam
  • 4,532
  • 3
  • 32
  • 44
  • Saying you can't find `q` is a bit like saying you can't find `master`, which is possible but a bit hard to believe. – JB. Sep 19 '13 at 12:15
  • @JB. You're right, I updated the question. There are a lot of commits after `q`. – antonagestam Sep 19 '13 at 12:32

3 Answers3

2

If the feature or release branches had unique names you should be able to find q on master by searching its merge commits for that unique name (e.g. by using gitk --merges and then entering a term in the Find field) because Git by default records the merged branch names in merge commit messages.

Otherwise, you could just search for the first merge commit on masterthat has g merged with a script similar to this one:

g=ad198bc
for i in $(git log --merges --reverse --format=%H); do
    revlist=$(git rev-list -1 $g --not $i)
    if [ $? -eq 0 ]; then
        if [ "$revlist" = "" ]; then
            echo "Merge commit $i has $g merged."
            exit
        fi
    fi
done
sschuberth
  • 28,386
  • 6
  • 101
  • 146
0

Assuming that you're Git history looks exactly as you have described:

            f---g---h--- feature
           /         \
      c---e---i---j---k---l--- release
     /                     \
-a--b---d---m---n---o---p---q---[hundreds of commits]--- master

Then one way you can find q is simply by examining your git log. Use

git log --oneline --graph

then in the less pager output (I'm assuming that you're using less as your pager), hit / and then type the sha for g, which will then cause less to search the git log output for that sha. Then simply scroll up a little in the output until you find q.

-1

I would suggest this:

git log --merges --ancestry-path g..q

--merges logs only merge commits, and --ancestry-path limits the commits to only those on the path between g and q. In this case it should show you both k and q.

twalberg
  • 59,951
  • 11
  • 89
  • 84