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

`git blame` Line Number Off-by-one

From
NMNuthan Munaiah <nm6061@rit.edu>
Date
Aug 7, 2020, 01:05 UTC
Message-ID
<emc6590292-832a-4a35-8815-d5707731d605@sanctum>
What did you do before the bug happened? (Steps to reproduce your issue)
  * Clone https://github.com/apache/tomcat
  * Run `git blame --root -leftw -L 21,21 -L 23,23 
51844327d8613448bb0bf9667e1a61e462e2043c^ -- 
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java`
What did you expect to happen? (Expected behavior)

`git blame` shows the last commit that modified lines 21 and 23 of `modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java` starting at the parent of `51844327d8613448bb0bf9667e1a61e462e2043c`.

``` $ git blame --root -leftw -L 21,21 -L 23,23 51844327d8613448bb0bf9667e1a61e462e2043c^ -- modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@apache.org> 1226896977 +0000 21) import java.util.ArrayList; c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@apache.org> 1226896977 +0000 23) import java.util.List; ```

What happened instead? (Actual behavior)

Line 23 is not shown in the `git blame` output. Instead, line 22 is shown.

``` $ git blame --root -leftw -L 21,21 -L 23,23 51844327d8613448bb0bf9667e1a61e462e2043c^ -- modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@apache.org> 1226896977 +0000 21) import java.util.ArrayList; c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@apache.org> 1226896977 +0000 22) import java.util.HashMap; ```

What's different between what you expected and what actually happened?

Line 23 is not shown in the `git blame` output. Instead line 22 is shown.

Anything else you want to add:
  * The issue is reproducible on git versions 2.28.0 (on Ubuntu 18.04.4 
LTS), 2.24.0 (on Ubuntu 18.04.3 LTS), 2.17.0 (on Ubuntu 18.04.4 LTS), 
and 2.27.0.windows.1 (on Microsoft Windows 10 Enterprise 10.0.19041 
Build 19041).
  * The addition of `--porcelain` does not resolve the issue.
  * The issue is not specific to a particular repository. For instance, 
the output from `git blame -L 1466,1466 -L 1468,1468  
35e69fc7cf9421ab04ffc9d52cb36d07fa12984a^ -- c/dec/decode.c` in a clone 
of https://github.com/google/brotli shows last commit that modified 
lines 1466 and 1467 (instead 1468).
  * The issue seems to present itself only when there is exactly one line 
in between two specifications of `-L`. For instance, `-L 20,20 -L 23,23` 
correctly blames lines 20 and 23, `-L 20,20 -L 21,21 -L 22,22 -L 23,23` 
correctly blames lines 20, 21, 22, and 23, `-L 23,23` correctly blames 
line 23, but `-L 21,21 -L 23,23` blames lines 21 and 22 (instead of 23).

[System Info] git version: git version 2.28.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 compiler info: gnuc: 7.5 libc info: glibc: 2.27 $SHELL (typically, interactive shell): <unset>

[Enabled Hooks]
Next: Jeff King
Message 1 of 16 in “`git blame` Line Number Off-by-one”
  1. Nuthan MunaiahAug 7, 2020
  2. Jeff KingAug 7, 2020
  3. Jeff KingAug 7, 2020
  4. Jeff KingAug 7, 2020
  5. Junio C HamanoAug 7, 2020
  6. Jeff KingAug 7, 2020
  7. Jeff KingAug 7, 2020
  8. 0/3 blame: fix bug in coalescing non-adjacent "-L" chunksJeff King, Aug 13, 2020
  9. 1/3 t8003: check output of coalesced blameJeff King, Aug 13, 2020
  10. Junio C HamanoAug 13, 2020
  11. Jeff KingAug 13, 2020
  12. 2/3 t8003: factor setup out of coalesce testJeff King, Aug 13, 2020
  13. 3/3 blame: only coalesce lines that are adjacent in resultJeff King, Aug 13, 2020
  14. Junio C HamanoAug 13, 2020
  15. Junio C HamanoAug 13, 2020
  16. Barret RhodenAug 13, 2020

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.