Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
845 views
in Technique[技术] by (71.8m points)

Why does git stash pop say that it could not restore untracked files from stash entry?

I had a bunch of staged and unstaged changes and I wanted to quickly switch to another branch and then switch back.

So I staged my changes using:

$ git stash push -a

(In hindsight I probably could have used --include-untracked instead of --all)

Then when I went to pop the stash I get a whole lot of errors along the lines of:

$ git stash pop
foo.txt already exists, no checkout
bar.txt already exists, no checkout
...
Could not restore untracked files from stash entry

There doesn't seem to be any changes restored from the stash.

I also tried $ git stash branch temp but that shows the same errors.

I did figure out a way around this which was to use:

$ git stash show -p | git apply

Disaster averted for now but this raises some questions.

Why did this error happen in the first place and how do I avoid it next time?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I managed to recreate your issue. It seems if you stash untracked files and then you create those files (in your example, foo.txt and bar.txt), then you have local changes to untracked files that would be overwritten when you apply git stash pop.

To get around this issue, you can use the following command. This will override any unsaved local changes so be careful.

git checkout stash -- .

Here is some further information I found on the previous command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...