All of lore.kernel.org
 help / color / mirror / Atom feed
* git stash save -u deletes ignored files without stashing them
@ 2015-12-13  7:51 Michael Brade
  2016-02-04  7:40 ` Kevin Locke
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Brade @ 2015-12-13  7:51 UTC (permalink / raw)
  To: git

Hi,

and it does so if .gitignore has not been committed yet. This is with
git version 2.6.3. To reproduce:

mkdir test
cd test
git init

echo "test" > test
echo "something.txt" > .gitignore

git add test .gitignore
git commit -a -m "init"

mkdir node_modules
echo "something" > node_modules/file.txt
echo "node_modules" >> .gitignore

git stash save -u

Now node_modules will be deleted even though it was ignored at the time
of the "git stash save -u". Apparently .gitignore is reverted first,
then the cleanup is done taking the new state of .gitignore into account
where node_modules is now untracked and not ignored anymore, thus
deleting it.

I think this should be considered a bug that can cause data loss, even
if only in rare cases.

thanks,
  Michael

PS: I'm not subscribed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git stash save -u deletes ignored files without stashing them
  2015-12-13  7:51 git stash save -u deletes ignored files without stashing them Michael Brade
@ 2016-02-04  7:40 ` Kevin Locke
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Locke @ 2016-02-04  7:40 UTC (permalink / raw)
  To: git; +Cc: Michael Brade

On Sun, 2015-12-13 at 7:51, Michael Brade wrote:
> Now node_modules will be deleted even though it was ignored at the time
> of the "git stash save -u". Apparently .gitignore is reverted first,
> then the cleanup is done taking the new state of .gitignore into account
> where node_modules is now untracked and not ignored anymore, thus
> deleting it.

Another effect of this, although obviously less severe, is that it can
create a stash which can not be applied without additional work:

git init
echo test.txt > .gitignore
git add .gitignore
git commit -m init
echo stuff > test.txt
echo > .gitignore
git stash -u

At this point the stash contains test.txt (untracked) and the changes
to .gitignore which unignore the file, but test.txt is also left in
the working directory.  Attempting to apply the stash produces the
following result:

$ git stash apply
test.txt already exists, no checkout
Could not restore untracked files from stash

So the user must remove it themselves, which can be confusing since
the file is not listed in `git stash show`, which doesn't include
untracked files.

Kevin

P.S.  Please CC me on replies.  Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-04  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-13  7:51 git stash save -u deletes ignored files without stashing them Michael Brade
2016-02-04  7:40 ` Kevin Locke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.