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

4 messages from 2008-05-22 to 2008-05-22. Participants: Steven A. Falco, Miklos Vajna, Jeff King.
Thread: https://gitlist.dev/t/13616

## Steven A. Falco, 2008-05-22 15:21

Subject: How can I figure out what commits relate to a given diff?
Message-ID: <48358F7E.6030401@harris.com>
URL: https://gitlist.dev/e/48358F7E.6030401%40harris.com

```
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, 2008-05-22 15:48

Subject: Re: How can I figure out what commits relate to a given diff?
Message-ID: <20080522154859.GM27724@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080522154859.GM27724%40genesis.frugalware.org
In-Reply-To: <48358F7E.6030401@harris.com>

```
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.

```

## Jeff King, 2008-05-22 16:04

Subject: Re: How can I figure out what commits relate to a given diff?
Message-ID: <20080522160414.GA11158@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080522160414.GA11158%40sigill.intra.peff.net
In-Reply-To: <48358F7E.6030401@harris.com>

```
On Thu, May 22, 2008 at 11:21:34AM -0400, Steven A. Falco wrote:

> 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

```

## Steven A. Falco, 2008-05-22 20:53

Subject: Re: How can I figure out what commits relate to a given diff?
Message-ID: <4835DD55.8080500@harris.com>
URL: https://gitlist.dev/e/4835DD55.8080500%40harris.com
In-Reply-To: <20080522154859.GM27724@genesis.frugalware.org>

```
Miklos Vajna wrote:
> 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

```
