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

Re: how to track the history of a line in a file

From
Ddavid@lang.hm <david@lang.hm>
Date
Jan 2, 2009, 22:43 UTC
Message-ID
<alpine.DEB.1.10.0901021439080.21567@asgard.lang.hm>
In-Reply-To
<20090102212655.GA24082@coredump.intra.peff.net>
On Fri, 2 Jan 2009, Jeff King wrote:
Show 10 quoted lines
> On Fri, Jan 02, 2009 at 02:13:32PM -0800, david@lang.hm wrote:
>
>> I have a need to setup a repository where I'm storing config files, and I
>> need to be able to search the history of a particular line, not just when
>> the last edit of the line was (which is what I see from git blame)
>
> As you figured out, the "manual" way is to just keep reblaming from the
> parent of each blame. Recent versions of "git gui blame" have a "reblame
> from parent" option in the context menu which makes this a lot less
> painful.
unfortunantly I am needing to do this from the command line.
Show 22 quoted lines
>> 57f8f7b6 (Linus Torvalds 2008-10-23 20:06:52 -0700 3) SUBLEVEL = 28
>>
>> what I would want it to show would be a list of the commits that have
>> changed this line.
>
> 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.

using the line number shouldn't be _that_ hard becouse git knows what lines came and went from the file, so it can calculate the new line number (and does with the -M option)

In my case I would consider 'the same line' to be any lines in the diff that were taken out when this line was put in

so in the usual case (for me) of

-oldline +newline

it's a 1-1 correspondence

if it's instead -oldline1 -oldline2 +newline1 +newline2

I can't know for sure which oldline corresponds to the newline, but the odds are very good that they are related, so if I widen the search to cover each of the lines I am probably good.

David Lang
Previous: Jeff KingNext: Jeff Whiteside
Message 3 of 17 in “how to track the history of a line in a file”
  1. david@lang.hmJan 2, 2009
  2. Jeff KingJan 2, 2009
  3. david@lang.hmJan 2, 2009
  4. Jeff WhitesideJan 2, 2009
  5. david@lang.hmJan 2, 2009
  6. david@lang.hmJan 2, 2009
  7. david@lang.hmJan 2, 2009
  8. Junio C HamanoJan 2, 2009
  9. david@lang.hmJan 3, 2009
  10. Thomas RastJan 3, 2009
  11. david@lang.hmJan 3, 2009
  12. david@lang.hmJan 2, 2009
  13. david@lang.hmJan 3, 2009
  14. Bernt HansenJan 6, 2009
  15. Miklos VajnaJan 6, 2009
  16. Bernt HansenJan 6, 2009
  17. Bernt HansenJan 6, 2009

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.