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

git grep: ^$ false match at end of file

From
OBOlly Betts <olly@survex.com>
Date
Jan 9, 2025, 23:52 UTC
Message-ID
<20250109235255.GA3418@survex.com>

git grep '^$' seems to match at the end of the file, reporting a line number one greater than the number of lines in that file. This does not match the behaviour of grep.

To reproduce:
$ git init -q git-grep-bug
$ cd git-grep-bug
$ echo test > test.txt
$ git add test.txt
$ git commit -m test
[master (root-commit) 55b48b26] test
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
$ git grep -n '^$'
test.txt:2:
$ grep -n '^$' test.txt
$
(The -n option isn't required to trigger it.)

I'm using the git 1:2.47.1-1 packages from Debian unstable. I can also reproduce with git 1:2.48.0~rc1+next.20250101-1 from Debian experimental.

Cheers,
    Olly
Next: Jeff King
Message 1 of 5 in “git grep: ^$ false match at end of file”
  1. Olly BettsJan 9, 2025
  2. Jeff KingJan 10, 2025
  3. Jeff KingJan 10, 2025
  4. Andreas SchwabJan 10, 2025
  5. Jeff KingJan 13, 2025

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.