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

Bug: Untracked file deleted by git-stash

From
MKMartin Kunev <martinkunev@gmail.com>
Date
May 10, 2018, 19:21 UTC
Message-ID
<20180510212152.08d2b9a7@martofr>
I stumbled upon the following issue with git 2.11.0 on Debian 9.
When a tracked file is removed and a directory with the same name is created, git-stash would delete the directory with all its contents. No warning is displayed and git stores no information about the deleted content (as far as I can tell). The following steps can be used to reproduce:
$ mkdir /tmp/bug; cd /tmp/bug
$ git init
Initialized empty Git repository in /tmp/bug/.git/
$ echo 'original file' > entry
$ git add entry
$ git commit -m 'entry added'
[master (root-commit) 483319e] entry added
 1 file changed, 1 insertion(+)
 create mode 100644 entry
$ rm entry
removed 'entry'
$ mkdir entry
$ echo 'data that will be destroyed' > entry/content
$ git status
On branch master
Changes not staged for commit:
    deleted:    entry

no changes added to commit $ ls -l total 4 drwxr-xr-x 2 martin root 4096 May 10 21:16 entry $ git stash Saved working directory and index state WIP on master: 483319e entry added HEAD is now at 483319e entry added

After the stash, the working tree contains only the regular file entry and the stash contains no information about the directory or its contents:

$ ls -l total 4 -rw-r--r-- 1 martin root 5 May 10 21:16 entry $ git status On branch master nothing to commit, working tree clean $ git stash show -p

diff --git a/entry b/entry
deleted file mode 100644
index 1269488..0000000
--- a/entry
+++ /dev/null
@@ -1 +0,0 @@
-original file
Message 1 of 1 in “Bug: Untracked file deleted by git-stash”
  1. Martin KunevMay 10, 2018

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.