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

Re: git stash save -u deletes ignored files without stashing them

From
Kevin Locke <kevin@kevinlocke.name>
Date
Feb 4, 2016, 07:40 UTC
Message-ID
<20160204074011.GA25382@kevinolos>
In-Reply-To
<566D236D.5090904@kde.org>
On Sun, 2015-12-13 at 7:51, Michael Brade wrote:
Show 5 quoted lines
> 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!
Previous: Michael Brade
Message 2 of 2 in “git stash save -u deletes ignored files without stashing them”
  1. Michael BradeDec 13, 2015
  2. Kevin LockeFeb 4, 2016

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.