Git development
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Till Friebe <friebetill@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Lost files after git stash && git stash pop
Date: Sat, 22 Jul 2023 23:44:33 +0200	[thread overview]
Message-ID: <20230722214433.3xfoebf7my5wsihf@tb-raspi4> (raw)
In-Reply-To: <5260C6A0-C53C-4F6D-B899-6AD8601F8458@gmail.com>

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.

However, I personally wonder if this is a bug or not.
First, Git is told to track a file called README/README
Then the file is removed, without telling Git.
And a new, unkown file appers on disk (which collides with the name
of the directory)

Using this sequence could have told Git, what is going on:
git mv README/README README2
rmdir README
git mv README2 README

(a temporary branch may be checked out, with the option
 to merge-squash the final result)


An other alternative could be to tell `git stash` to care
about untracked file(s):

git stash -u
git stash pop

Which will refuse to apply the stash.

A third alternative could be to keep the file inside an
editor, to have the content still available.

However, it would/could be nice, if files are not simply deleted,
but saved into a "lost+found" folder, or a wastebasket kind of thing.

But which files ?
Those that are untracked ?
They may be important (local config files, passwords, help scripts, ...)
or not (.o files from a C compiler).

In some older discussions they had been named "precious" files.
But, as far as I remember, there was no easy solution.
In that sense I don't have a better answer.
Others may have.

Thanks for reporting, it make me read [1] and come to the conclusion
that it is sometimes safer to checkout out a temporary branch, commit
everything and clean up later, rather than relying too much on
`git stash`


<https://stackoverflow.com/questions/835501/how-do-you-stash-an-untracked-file>
>
> What's different between what you expected and what actually happened?
> The file doesn't exist anymore and I can't recover it.
>
> Anything else you want to add:
> This is just a reproducible example.
>

  reply	other threads:[~2023-07-22 21:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 17:31 Lost files after git stash && git stash pop Till Friebe
2023-07-22 21:44 ` Torsten Bögershausen [this message]
2023-07-23 10:01   ` Phillip Wood
2023-07-23 20:52     ` Torsten Bögershausen
2023-07-24  9:59       ` Phillip Wood
2023-08-08 17:26 ` [PATCH v1 1/1] git stash needing mkdir deletes untracked file tboegi
2023-08-08 18:03   ` Torsten Bögershausen
2023-08-08 19:28   ` Eric Sunshine
2023-08-09 13:15   ` Phillip Wood
2023-08-09 18:47     ` Torsten Bögershausen
2023-08-15  9:15       ` Phillip Wood
2023-08-15 15:25         ` Torsten Bögershausen
2023-08-15 18:03         ` Junio C Hamano
2023-08-09 20:57     ` Junio C Hamano
2023-08-15  9:16       ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230722214433.3xfoebf7my5wsihf@tb-raspi4 \
    --to=tboegi@web.de \
    --cc=friebetill@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox