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

Re: Lost files after git stash && git stash pop

From
Torsten Bögershausen <tboegi@web.de>
Date
Jul 23, 2023, 20:52 UTC
Message-ID
<20230723205239.5snlakmd5ocy67q2@tb-raspi4>
In-Reply-To
<a373a659-a232-77cb-a177-a517b1f228f4@gmail.com>
On Sun, Jul 23, 2023 at 11:01:29AM +0100, Phillip Wood wrote:
Show 34 quoted lines
> On 22/07/2023 22:44, Torsten Bögershausen wrote:
> > On Fri, Jul 21, 2023 at 07:31:53PM +0200, Till Friebe wrote:
> > > Thank you for filling out a Git bug report!
> > > Please answer the following questions to help us understand your issue.
> > >
> > > What did you do before the bug happened? (Steps to reproduce your issue)
> > > ```
> > > git init
> > > mkdir README
> > > touch README/README
> > > git add .
> > > git commit -m "Init project"
> > > echo "Test" > README/README
> > > mv README/README README2
> > > rmdir README
> > > mv README2 README
> > > git stash
> > > git stash pop
> > > ```
> > >
> > > What did you expect to happen? (Expected behavior)
> > > I expected that after the `git stash pop` the README file would be back.
> > >
> > > What happened instead? (Actual behavior)
> > > This README with "Test" file was deleted and I lost 5 hours of work.
> >
> > That is always sad to hear, when work is lost.
>
> Indeed it is. Thanks Till for providing an easy reproducer.
>
> > However, I personally wonder if this is a bug or not.
>
> I think whenever git overwrites an untracked file without the user passing
> some option indicating that they want to do so it is a bug.
OK, agreed after reading the next sentence.
Show 8 quoted lines
> For example "git
> checkout" refuses to overwrite untracked files by default. Sadly this seems
> to be a known bug in do_push_stash() where we are using "git reset --hard"
> to remove the stashed changes from the working copy. This was documented in
> 94b7f1563a (Comment important codepaths regarding nuking untracked
> files/dirs, 2021-09-27). The stash implementation does a lot of necessary
> forking of subprocesses, in this case I think it would be better to call
> unpack_trees() directly with UNPACK_RESET_PROTECT_UNTRACKED.
Thanks for the fast response.

This is not an area of Git, where I have much understanding of the code. But is seems as if pop_stash() in builtin/stash.c (and the called functions) seems to be the problem here ?

Previous: Phillip WoodNext: Phillip Wood
Message 4 of 15 in “Lost files after git stash && git stash pop”
  1. Till FriebeJul 21, 2023
  2. Torsten BögershausenJul 22, 2023
  3. Phillip WoodJul 23, 2023
  4. Torsten BögershausenJul 23, 2023
  5. Phillip WoodJul 24, 2023
  6. 1/1 git stash needing mkdir deletes untracked filetboegi@web.de, Aug 8, 2023
  7. Torsten BögershausenAug 8, 2023
  8. Eric SunshineAug 8, 2023
  9. Phillip WoodAug 9, 2023
  10. Torsten BögershausenAug 9, 2023
  11. Phillip WoodAug 15, 2023
  12. Torsten BögershausenAug 15, 2023
  13. Junio C HamanoAug 15, 2023
  14. Junio C HamanoAug 9, 2023
  15. Phillip WoodAug 15, 2023

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.