bug report: `git stash save -u` deletes directory whose contents are .gitignored
- From
- lennart 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