{"thread":{"id":"13616","subject":"How can I figure out what commits relate to a given diff?","startedAt":"2008-05-22T15:21:34Z","lastAt":"2008-05-22T20:53:41Z","messageCount":4,"participants":["Steven A. Falco","Miklos Vajna","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"77476","messageId":"48358F7E.6030401@harris.com","threadId":"13616","inReplyTo":null,"subject":"How can I figure out what commits relate to a given diff?","fromName":"Steven A. Falco","fromEmail":"sfalco@harris.com","sentAt":"2008-05-22T15:21:34Z","receivedAt":"2008-05-22T15:21:34Z","isPatch":false,"sender":{"key":"sfalco@harris.com","avatar":null},"body":"I have a patch file, and I'd like to figure out which commits were used\nto produce it.\n\nFor example, one of the diffs in the patch file begins with:\n\ndiff --git a/Makefile b/Makefile\nindex 9ceadaa..ad31bc6 100644\n\nIs there a way to map a blob SHA1 to a commit?  In this example, I'd\nlike to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go\nthe other way, seeing what is in a commit, but I've not been able to\nfind a method for going \"backwards\" from a blob to a commit.\n\n    Thanks,\n    Steve\n"},{"id":"77477","messageId":"20080522154859.GM27724@genesis.frugalware.org","threadId":"13616","inReplyTo":"48358F7E.6030401@harris.com","subject":"Re: How can I figure out what commits relate to a given diff?","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-05-22T15:48:59Z","receivedAt":"2008-05-22T15:48:59Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Thu, May 22, 2008 at 11:21:34AM -0400, \"Steven A. Falco\" <sfalco@harris.com> wrote:\n> Is there a way to map a blob SHA1 to a commit?  In this example, I'd\n> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go\n> the other way, seeing what is in a commit, but I've not been able to\n> find a method for going \"backwards\" from a blob to a commit.\n\nSomething like:\n\nfor i in `git rev-list HEAD`\ndo\n        git ls-tree -r $i|grep -q cb4e8ed && echo \"$i contains cb4e8ed\"\ndone\n\ncould do it for you.\n\nI don't think there is a --contains for blobs, like git branch\n--contains works for commits.\n"},{"id":"77478","messageId":"20080522160414.GA11158@sigill.intra.peff.net","threadId":"13616","inReplyTo":"48358F7E.6030401@harris.com","subject":"Re: How can I figure out what commits relate to a given diff?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-05-22T16:04:14Z","receivedAt":"2008-05-22T16:04:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 22, 2008 at 11:21:34AM -0400, Steven A. Falco wrote:\n\n> For example, one of the diffs in the patch file begins with:\n> \n> diff --git a/Makefile b/Makefile\n> index 9ceadaa..ad31bc6 100644\n> \n> Is there a way to map a blob SHA1 to a commit?  In this example, I'd\n> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go\n> the other way, seeing what is in a commit, but I've not been able to\n> find a method for going \"backwards\" from a blob to a commit.\n\nMiklos suggested a way of looking up trees and commits which contain\nblobs, but you can also look for that specific change of blobs:\n\n  git log --pretty=format:'%h %s' --raw |\n    perl -00 -ne 'print if /9ceadaa.*ad31bc6/'\n\n-Peff\n"},{"id":"77494","messageId":"4835DD55.8080500@harris.com","threadId":"13616","inReplyTo":"20080522154859.GM27724@genesis.frugalware.org","subject":"Re: How can I figure out what commits relate to a given diff?","fromName":"Steven A. Falco","fromEmail":"sfalco@harris.com","sentAt":"2008-05-22T20:53:41Z","receivedAt":"2008-05-22T20:53:41Z","isPatch":false,"sender":{"key":"sfalco@harris.com","avatar":null},"body":"Miklos Vajna wrote:\n> On Thu, May 22, 2008 at 11:21:34AM -0400, \"Steven A. Falco\" <sfalco@harris.com> wrote:\n>> Is there a way to map a blob SHA1 to a commit?  In this example, I'd\n>> like to map 9ceadaa and ad31bc6 to their commits.  It seems easy to go\n>> the other way, seeing what is in a commit, but I've not been able to\n>> find a method for going \"backwards\" from a blob to a commit.\n> \n> Something like:\n> \n> for i in `git rev-list HEAD`\n> do\n>         git ls-tree -r $i|grep -q cb4e8ed && echo \"$i contains cb4e8ed\"\n> done\n> \n> could do it for you.\n> \n> I don't think there is a --contains for blobs, like git branch\n> --contains works for commits.\n\nThanks!  It found the commit I needed.\n\n\tSteve\n"}]}