threads / discuss / 13616

How can I figure out what commits relate to a given diff?

Subject: How can I figure out what commits relate to a given diff?

## tl;dr

4 messages between May 22, 2008 and May 22, 2008.

replies: 3people: 3as markdown or json

Steven A. Falco· May 22, 2008, 15:21 UTC · lore

I have a patch file, and I'd like to figure out which commits were used to produce it.

For example, one of the diffs in the patch file begins with:
diff --git a/Makefile b/Makefile
index 9ceadaa..ad31bc6 100644

Is there a way to map a blob SHA1 to a commit?  In this example, I'd
like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go
the other way, seeing what is in a commit, but I've not been able to
find a method for going "backwards" from a blob to a commit.

    Thanks,
    Steve
Miklos Vajna· May 22, 2008, 15:48 UTC · re: Steven A. Falco · lore

Re: How can I figure out what commits relate to a given diff?

On Thu, May 22, 2008 at 11:21:34AM -0400, "Steven A. Falco" <sfalco@harris.com> wrote:
> Is there a way to map a blob SHA1 to a commit?  In this example, I'd
> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go
> the other way, seeing what is in a commit, but I've not been able to
> find a method for going "backwards" from a blob to a commit.
Something like:
for i in `git rev-list HEAD`
do
        git ls-tree -r $i|grep -q cb4e8ed && echo "$i contains cb4e8ed"
done
could do it for you.

I don't think there is a --contains for blobs, like git branch --contains works for commits.

Steven A. Falco· May 22, 2008, 20:53 UTC · re: Miklos Vajna · lore

Re: How can I figure out what commits relate to a given diff?

Miklos Vajna wrote:
Show 17 quoted lines
> On Thu, May 22, 2008 at 11:21:34AM -0400, "Steven A. Falco" <sfalco@harris.com> wrote:
>> Is there a way to map a blob SHA1 to a commit?  In this example, I'd
>> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go
>> the other way, seeing what is in a commit, but I've not been able to
>> find a method for going "backwards" from a blob to a commit.
> 
> Something like:
> 
> for i in `git rev-list HEAD`
> do
>         git ls-tree -r $i|grep -q cb4e8ed && echo "$i contains cb4e8ed"
> done
> 
> could do it for you.
> 
> I don't think there is a --contains for blobs, like git branch
> --contains works for commits.
Thanks!  It found the commit I needed.
	Steve
Jeff King· May 22, 2008, 16:04 UTC · re: Steven A. Falco · lore

Re: How can I figure out what commits relate to a given diff?

On Thu, May 22, 2008 at 11:21:34AM -0400, Steven A. Falco wrote:
Show 9 quoted lines
> For example, one of the diffs in the patch file begins with:
> 
> diff --git a/Makefile b/Makefile
> index 9ceadaa..ad31bc6 100644
> 
> Is there a way to map a blob SHA1 to a commit?  In this example, I'd
> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go
> the other way, seeing what is in a commit, but I've not been able to
> find a method for going "backwards" from a blob to a commit.

Miklos suggested a way of looking up trees and commits which contain blobs, but you can also look for that specific change of blobs:

  git log --pretty=format:'%h %s' --raw |
    perl -00 -ne 'print if /9ceadaa.*ad31bc6/'
-Peff

← back to recent threads