Re: how to track the history of a line in a file
- From
- david@lang.hm <david@lang.hm>
- Date
- Jan 2, 2009, 23:01 UTC
- Message-ID
- <alpine.DEB.1.10.0901021459480.21567@asgard.lang.hm>
- In-Reply-To
- <20090102212655.GA24082@coredump.intra.peff.net>
On Fri, 2 Jan 2009, Jeff King wrote:
Show 17 quoted lines
> The tricky thing here is what is "this line"? Using the line number > isn't right, since it will change based on other content coming in and > out of the file. You can keep drilling down by reblaming parent commits, > but remember that each time you do that you are manually looking at the > content and saying "Oh, this is the line I am still interested in." So I > a script would have to correlate the old version and new version of the > line and realize how to follow the "interesting" thing. > > In your case, I think you want to see any commit in Makefile which > changed a line with SUBLEVEL in it. Which is maybe easiest done as: > > git log -z -p Makefile | > perl -0ne 'print if /\n[+-]SUBLEVEL/' | > tr '\0' '\n' > > and is pretty fast. But obviously we're leveraging some content-specific > knowledge about what's in the Makefile.
Ok, I hacked togeather a quick bash script to try this
#!/bin/bash line=`git blame -L /$1/,+1 -M $2` COMMIT=`echo $line |cut -f 1 -d " "` foundline=`echo $line |cut -f 6 -d " "|sed s/")"//` echo "$foundline $COMMIT" echo "$line" while [ "$COMMIT" != "" ] ;do echo "git blame -L $foundline,+1 -M $2 $COMMIT^" line=`git blame -L $foundline,+1 -M $2 $COMMIT^` COMMIT=`echo $line |cut -f 1 -d " "` foundline=`echo $line |cut -f 6 -d " "|sed s/")"//` echo "$line" done
the problem that this has is that line 3 of $COMMIT may not be line 3 of $COMMIT^, and if they aren't it ends up hunting down the wrong data
either that or I am not understanding the output of git blame properly (also very possible)
David Lang