Reputation: 1243
I'm trying to find the origin of a bug in our code base. I have the SHA of a commit that I suspect caused the breakage, but I also know the date where the bug started to appear. I want to check when a given commit was merged into our main branch.
Is there an easy way to do that?
Upvotes: 4
Views: 145
Reputation: 2711
I'll assume that your main branch is master
and that the SHA you suspect is in $SHA
.
First, find the merge commits that are in master
but not in $SHA
's history:
$ git log --merges --oneline $SHA..master
Then, test each of these merge commits to determine which one contains $SHA
. Let's assume a given merge commit ID is in $MERGE
. You can list all of the commits that were merged into master
by this commit with git log --oneline $MERGE^..$MERGE
.
(This works because $MERGE^
is the [first] parent of $MERGE
, i.e. the snapshot of master
before the merge, so $MERGE^..$MERGE
is listing the commits in $MERGE
but not in $MERGE^
, i.e. the commits in $MERGE
but not in master
before the merge.)
Then you can grep
for your target $SHA
:
$ git log --oneline $MERGE^..$MERGE | grep ^$SHA
The first merge commit that gets any of its output past grep
is your winner. Once you have identified the commit, you can git show
it for more info.
$ git show $MERGE
I'd be interested in an easier way to do this, if anybody knows of one.
Upvotes: 1
Reputation: 70235
You can find the suspect commit based on a date with:
git log --before=<date> -n 1
This, or something with a date a day or two before, could be the 'good' starting point for your git bisect
.
Upvotes: 1
Reputation: 55573
git branch --contains SHA1
should print you all the branches which contain the given commit.
Upvotes: 2
Reputation: 8836
git bisect
should help you locate the bug quite nicely.
https://www.kernel.org/pub/software/scm/git/docs/git-bisect.html
http://git-scm.com/book/en/Git-Tools-Debugging-with-Git#Binary-Search
As for the commit SHA you are targeting, just run git log
on it, and it will tell you all about the commit (date, author, etc.). Run git log -p
on it to see what changes that commit made.
Upvotes: 5