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

buggy smudge/clean of empty files

From
Joey Hess <id@joeyh.name>
Date
May 22, 2025, 19:01 UTC
Message-ID
<aC90kn2mE93DCJEH@kitenet.net>

git seems to be buggy in its handling of empty files when smudge/clean filters are used.

I've attached a script setup_smudge_clean.sh, which configures a git repository to use a very simple smudge and clean filter pair for all files. The clean filter prepends a line "hi" to the file content, and the smudge filter removes the line. There is nothing very special about this smudge/clean, it's just a simple one for the sake of an example.

Here's the bug:

# git init repo # cd repo # sh ~/setup_smudge_clean.sh # echo foo > foofile # git add foofile # git diff # touch emptyfile # git add emptyfile # git commit -m added # git status On branch master nothing to commit, working tree clean # git diff

diff --git a/emptyfile b/emptyfile
--- a/emptyfile
+++ b/emptyfile
@@ -1 +0,0 @@
-hi

emptyfile is unchanged, as git status shows, so why is git diff displaying
a change?

It seems that git diff runs the clean filter (GIT_TRACE shows it does),
but it must ignore its output when the file is empty, and always use an empty
file as the current content for the diff. Which differs from what was staged.
-- 
see shy jo
Next: Jeff King
Message 1 of 3 in “buggy smudge/clean of empty files”
  1. Joey HessMay 22, 2025
  2. Jeff KingMay 22, 2025
  3. Junio C HamanoMay 22, 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.