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

bug report: `git stash save -u` deletes directory whose contents are .gitignored

From
LSlennart spitzner <len48@web.de>
Date
Oct 13, 2015, 22:48 UTC
Message-ID
<561D8A23.2090601@web.de>
hi,
- `git stash save -u` deletes a directory, even though the _contents_
of that directory are .gitignored (e.g. "foo/*" in .gitignore).
Detailed reproduction below.
- The behaviour is not present when instead .gitignoring the directory
itself (e.g. "foo"). This does imo not excuse the behaviour of the
described case.
- The behaviour is not present with just `git stash save`.
- The expected behaviour is: Only files listed in `git status` are
stashed away; other things are left untouched. Potential exception:
empty directories.
- I am aware that `git stash save -u` is supposed to have semantics
involving the equivalent of `reset --hard` and `clean -f`. Neither of
those expose the directory-deletion behaviour.
additional comments, not directly relevant to this bug:
- both `git stash save; git stash pop` and `git stash save -u; git
stash pop` should ideally behave as an "identity effect". The latter
might affect the index (i.e. have an effect equivalent to `git reset`
or something in that direction). Any other effect / special cases are
bad interface design imo. If a differing design was chosen on purpose,
i am thankful for pointers on the reasoning.
- no, i luckily did not truely lose files due to the current behaviour.
lennart
----
reproduction:
> git init
Initialized empty Git repository in $SOMEDIR/.git/
Show 7 quoted lines
> mkdir ignore-contents
> echo "ignore-contents/*" > .gitignore
> git add .gitignore
> git commit -m "initial" > /dev/null
> touch ignore-contents/blah.txt
> touch abc.txt
> git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
  abc.txt

nothing added to commit but untracked files present (use "git add" to track)

> ls -1a

. .. abc.txt .git .gitignore ignore-contents

> git stash save -u

Saved working directory and index state WIP on master: adc468b initial HEAD is now at adc468b initial

> ls -1a

. .. .git .gitignore

> git stash pop &> /dev/null
> ls -1a

. .. abc.txt .git .gitignore

> git --version
git version 2.6.1
Message 1 of 1 in “bug report: `git stash save -u` deletes directory whose contents are .gitignored”
  1. lennart spitznerOct 13, 2015

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.