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

Re: Bugreport: git log -L

From
Kristofer Karlsson <krka@spotify.com>
Date
Sep 21, 2026, 09:49 UTC
Message-ID
<CAL71e4Nw+-bmc0sCOC+L9VyxYG6MwRf-XbXDDWO1grOH=WbEOw@mail.gmail.com>
In-Reply-To
<41c54b809eb1490fb467ba0fd4c5a8cf@yadro.com>
On Mon, 21 Sept 2026 at 09:49, Nikita Makarov <n.makarov@yadro.com> wrote:
Show 36 quoted lines
>
> Hello, I have the found the strange behavior of "git log -L" command with python function.
> It is counting a blank line that sits after a function's last statement as part of that function.
> This happens only when the function is at the end of a file.
>
> The way to reproduce that
>
> git init repro && cd repro
> git config user.email t@t && git config user.name t
>
> printf 'def foo():\n    return 1\n\n' > bug.py
> git add bug.py && git commit -qm c1
>
> printf 'def foo():\n    return 1\n' > bug.py
> git add bug.py && git commit -qm c2
>
> Then do
>
> git log -L :'foo':bug.py
>
> And you'll see
>
> Author: t <t@t>
> Date:   Fri Sep 18 18:21:10 2026 +0300
>
>     c2
>
> diff --git a/bug.py b/bug.py
> --- a/bug.py
> +++ b/bug.py
> @@ -1,2 +1,3 @@
>  def foo():
>      return 1
> +
>
> Though I expect that commit "c2" should never appear in log, since the changes from it doesn't affect the functions body at all.

I tried to reproduce this but failed to do so. I first started wondering if this meant the bug had been fixed in master already, but then I also failed to reproduce it on 2.43.

I think the reproduction steps were wrong here, perhaps you meant to put the double newline in c2 instead of in c1? Because if I change that, I can reproduce it.

So the steps should have:
    printf 'def foo():\n    return 1\n' > bug.py
    git add bug.py && git commit -qm c1
    printf 'def foo():\n    return 1\n\n' > bug.py
    git add bug.py && git commit -qm c2
instead.
I think I should be able to submit a fix for this shortly.

Thanks, Kristofer

Previous: Nikita MakarovNext: Johannes Sixt
Message 2 of 4 in “Bugreport: git log -L”
  1. Nikita MakarovSep 21, 2026
  2. Kristofer KarlssonSep 21, 2026
  3. Johannes SixtSep 21, 2026
  4. Tim TassonisSep 21, 2026

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.