git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Blaming diffs

From
Mike Hommey <mh@glandium.org>
Date
Sep 16, 2007, 17:16 UTC
Message-ID
<20070916171635.GA8868@glandium.org>
In-Reply-To
<20070916170534.GU22865@planck.djpig.de>
On Sun, Sep 16, 2007 at 07:05:35PM +0200, Frank Lichtenheld <frank@lichtenheld.de> wrote:
Show 19 quoted lines
> On Sun, Sep 16, 2007 at 06:38:29PM +0200, Mike Hommey wrote:
> > It seems to me there is no tool to "blame diffs", i.e. something to know
> > what commit(s) is(are) responsible for a set of changes.
> > 
> > For example, the following script tries to get the set of commits
> > involved in the changes between $A and $B. Note it only works for text
> > additions. 
> > 
> > git diff --unified=0 $A $B | awk 'BEGIN { FS="(^(--- a/|+++ b/)|^@@ -[0-9,]+ \\+| @@)" } /^---/ || ( /^+++ b\/(.*)/ && file=="" ) { file = $2 } /^@@/ {split($2, a, /,/); a[2] = a[2] ? a[2] + a[1] - 1 : a[1]; print "git blame -l -L " a[1] "," a[2], "'$A..$B'", file }' | sh | cut -f 1 -d " " | sort -u
> > 
> > Has anyone tried to work on something similar yet ?
> > 
> > If not, as git users, what kind of output would you expect from such a
> > tool, and where do you think this should lie (extension to git diff, or
> > separate tool) ?
> 
> What do you use for $A and $B? commits? What is the difference between
> your script and "git log --pretty=format:%H $A..$B"
> then?

In my typical usecase, $A is upstream and $B is HEAD. What happens is that my work branch includes some changes that have been merged upstream and some others that are not yet, or won't because it's not appropriate. I obviously occasionally merge the upstream branch back, in which case my changes that were committed upstream don't appear in a git diff $A $B anymore.

git log --pretty=format:%H $A..$B would give me the list of all commits that occurred on my branch, while my script only gives the commits containing changes that are still not applied upstream.

Mike
Previous: Frank LichtenheldNext: Christian Couder
Message 3 of 7 in “Blaming diffs”
  1. Mike HommeySep 16, 2007
  2. Frank LichtenheldSep 16, 2007
  3. Mike HommeySep 16, 2007
  4. Christian CouderSep 17, 2007
  5. Shawn O. PearceSep 17, 2007
  6. Christian CouderSep 17, 2007
  7. Junio C HamanoSep 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.