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

BUG: git commit -a crashes with "unable to stat" during unresolved merge

From
NGNick Golden <nreesegolden@gmail.com>
Date
Mar 31, 2026, 21:53 UTC
Message-ID
<CAF6hZH5TyFBm5H_fcVyaf1aw-mPsVbAmNvkUGCMoQYYCX1+HRQ@mail.gmail.com>
Hello,
I found a reproducible bug in `git commit -a`.

With an unresolved merge conflict present, if a different tracked file has been deleted from the working tree, `git commit -a` can crash with:

    fatal: unable to stat 'bystander.txt': No such file or directory
I can reproduce this reliably with Git 2.53.0 on macOS in a fresh repository.
To reproduce:
1. Create two tracked files with identical content.
2. Create a merge conflict on one of them.
3. Delete the other tracked file from the working tree.
4. Run `git commit -a -m test`.
Expected:

Git should either stage the deletion and then stop because of the unresolved merge, or refuse the commit because of the unresolved merge, but not crash trying to stat the deleted path.

Actual:
Git aborts with:
    fatal: unable to stat 'bystander.txt': No such file or directory
Reproducer script follows.
Possible cause:

This appears to involve rename detection during `add_files_to_cache()`: the deleted file gets paired with the unmerged path, and a later index update tries to `stat()` the deleted path.

Thanks,

Nick Golden nreesegolden@gmail.com

---8<--- #!/bin/sh set -eu

repro_dir="$(mktemp -d "${TMPDIR:-/tmp}/git-commit-a-rename-crash.XXXXXX")" echo "Working in: $repro_dir" cd "$repro_dir"

git init -b main git config user.name "Test User" git config user.email "test@example.com"

i=1
while [ "$i" -le 100 ]; do
    printf 'line %s: shared content that is identical across both files\n' "$i"
    i=$((i + 1))
done > conflict.txt
cp conflict.txt bystander.txt

git add conflict.txt bystander.txt git commit -m "initial"

git checkout -b feature perl -0pi -e 's/line 50:.*$/line 50: FEATURE BRANCH CHANGE/m' conflict.txt git add conflict.txt git commit -m "feature"

git checkout main perl -0pi -e 's/line 50:.*$/line 50: MAIN BRANCH CHANGE/m' conflict.txt git add conflict.txt git commit -m "main"

git merge feature || true rm bystander.txt

set +e output="$(git commit -a -m test 2>&1)" status=$? set -e

printf '%s\n' "$output" printf 'exit status: %s\n' "$status"

case "$output" in
    *"fatal: unable to stat 'bystander.txt': No such file or directory"*)
        echo "Bug reproduced."
        exit 0
        ;;
    *)
        echo "Did not reproduce the expected failure."
        exit 1
        ;;
esac
Next: blindmansion
Message 1 of 5 in “BUG: git commit -a crashes with "unable to stat" during unresolved merge”
  1. Nick GoldenMar 31, 2026
  2. read-cache: disable renames in add_files_to_cacheblindmansion, Apr 1, 2026
  3. Junio C HamanoApr 1, 2026
  4. read-cache: disable renames in add_files_to_cacheNick Golden, Apr 1, 2026
  5. Blind MansionApr 1, 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.