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

Re: How to `git blame` individual characters?

From
Christian Couder <christian.couder@gmail.com>
Date
Mar 27, 2018, 06:01 UTC
Message-ID
<CAP8UFD3TPfWtpT8RLGBL2V+M+nkpGEYVa8Y_c68u4Lw4zPyW5g@mail.gmail.com>
In-Reply-To
<CAA6PgK7L04VoHT7A8M_mwq5kA+9BiQxrd6iPjPHOpa4=Z3futw@mail.gmail.com>
Hi,
On Tue, Mar 27, 2018 at 2:18 AM, Jan Keromnes <janx@linux.com> wrote:
Show 5 quoted lines
> Dear Git developers,
>
> I'd like to understand what would be required to run `git blame` on
> individual characters instead of full lines. Could you please point me
> in the right direction?

You might want to take a look at cregit (https://github.com/cregit/cregit) and maybe at other work from the people who developed it.

There are links related to this tool in: https://git.github.io/rev_news/2017/05/17/edition-27/

Show 45 quoted lines
> Someone asked a similar question about "Word-by-word blame/annotate"
> on StackOverflow a few years ago, and one of the replies said:
>
>> Git tracks changes snapshot by snapshot. The line-based format is calculated on-the-fly, and it would also be possible to have a word-based format.
>
> Source: https://stackoverflow.com/q/17758008/3461173
>
> This leaves me hopeful that a character-based format can somehow be
> achieved. Here is a fake example to illustrate what I'm looking for:
>
>         $ cat myscript.js
>         for (int foo = 0; foo <= 11; foo++) { console.log(foo); }
>         $ git blame --character-based --pseudo-json myscript.js
>         [
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "for (int " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " = 0; " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " <= " },
>             { "commit": "cd1234ab", "summary": "Go up to 11",
> "characters": "11" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "; " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "++) { console.log(" },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": ")" },
>             { "commit": "d1234abc", "summary": "Add missing
> semicolon", "characters": ";" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " }" }
>         ]
>
> What would be the most direct way to achieve such a character-based
> blame/annotate? Should I write some sort of Git extension, or hack
> into Git's source code?

I think the "Token-based authorship information from Git" article (https://lwn.net/Articles/698425/) is about that.

Show 5 quoted lines
> E.g. I looked for an option in `git-blame` or `git-annotate` to change
> the "next line boundary" from "carret return" (line-based blame) to
> "any whitespace" (word-based blame) or "character-by-character"
> (character-based blame), but I didn't find it. Could this be
> implemented in `blame.c`? If so, which methods would need tweaking?
I don't think this is implemented in Git. Do you really need that in git itself?
Previous: Jan Keromnes
Message 2 of 2 in “How to `git blame` individual characters?”
  1. Jan KeromnesMar 27, 2018
  2. Christian CouderMar 27, 2018

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.