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

Bug: Checkout in sparse mode can overwrite uncommited files

From
Ccharmocc <charmocc@proton.me>
Date
Jun 19, 2026, 16:31 UTC
Message-ID
<15FXjc8hV3WTRkSg1-PMUqlEFqWxJ5iw5qVbO9WoMX0NEyB4l1AOGSOhtBsxZbgTYGjzZfLJoFr9cyaL9_5Jazwa1OQGPzS7_MCTnkfUJvQ=@proton.me>
Hey. Today I discovered inconsistent behavior in sparse mode that may lead to data loss during initial checkout. Please have a look.
What did you do before the bug happened? (Steps to reproduce your issue)

$ git init foo $ cd foo $ echo 1 > file $ git add file $ git commit -m 'test' $ cd ..

$ git clone --no-checkout foo bar
$ cd bar
$ echo 2 > file
$ git checkout
error: The following untracked working tree files would be overwritten by checkout:
	file
Please move or remove them before you switch branches.
Aborting
$ cat file
2
$ git sparse-checkout set
$ git checkout
warning: The following paths were already present and thus not updated despite sparse patterns:
	file

After fixing the above paths, you may want to run `git sparse-checkout reapply`. Your branch is up to date with 'origin/master'. $ cat file 1

What did you expect to happen? (Expected behavior)
Checkout should fail due to uncommited changes
What happened instead? (Actual behavior)
After enabling sparse mode checkout overwrites file in working directory
What's different between what you expected and what actually happened?
In normal mode checkout is aborted correctly but in sparse it overwrites data and gives misleading message
Anything else you want to add:
[System Info]
git version:
git version 2.53.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
rust: disabled
gettext: enabled
libcurl: 8.18.0
zlib: 1.3.1
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1
uname: Linux 7.0.0-22-generic #22-Ubuntu SMP PREEMPT_DYNAMIC Mon May 25 15:54:34 UTC 2026 x86_64
compiler info: gnuc: 15.2
libc info: glibc: 2.43
$SHELL (typically, interactive shell): /bin/bash
[Enabled Hooks]
Message 1 of 1 in “Bug: Checkout in sparse mode can overwrite uncommited files”
  1. charmoccJun 19, 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.