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

Re: git stash data loss

From
Jeff King <peff@peff.net>
Date
Jul 27, 2012, 13:50 UTC
Message-ID
<20120727135051.GA10303@sigill.intra.peff.net>
In-Reply-To
<20120727132953.GA8263@sigill.intra.peff.net>
On Fri, Jul 27, 2012 at 09:29:53AM -0400, Jeff King wrote:
Show 19 quoted lines
> If we put actual files inside "x", which git does track, then they would
> be part of the stash, and should be properly retained. But they're not:
> 
>   $ rm x && mkdir x && echo foo >x/file
> 
> Now we have some precious contents in the form of "x/file". They are
> untracked by git, but git should be careful about removing them.
> 
>   $ git stash
>   Saved working directory and index state WIP on master: 2d32d3a initial
>   HEAD is now at 2d32d3a initial
>   $ ls -l x
>   -rw-r--r-- 1 peff peff 0 Jul 27 09:19 x
>   $ git stash show --raw
>   :100644 000000 e69de29... 0000000... D  x
> 
> Now this _is_ data loss. Stash blows away untracked files inside the
> directory, but does not record them in the resulting stash. And that
> should be fixed.

Hrm. The problem is that after creating the stash, we then run "git reset --hard" to drop the changes that we just stashed. But that is not always accurate. It will not usually touch untracked files, but it might if they have D/F conflicts with tracked files. So we need to replace that "git reset --hard" with some safer command that will notice we are about to overwrite untracked files. But I am not sure what that command would be.

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 7 in “git stash data loss”
  1. Aleksandr PryimakJul 27, 2012
  2. Jeff KingJul 27, 2012
  3. Jeff KingJul 27, 2012
  4. Junio C HamanoAug 17, 2012
  5. Jeff KingAug 21, 2012
  6. Junio C HamanoSep 14, 2012
  7. Aleksandr PriymakJul 27, 2012

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.