Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git - Why can't stash be applied to the working directory?

I cannot apply stash back to the working directory.

Little story:

First I tried to push some committed changes, but it said: "no you can't, pull first"... OK then, I'll pull things from GitHub and then push my changes. When I tried to pull, it said that I had changes that would be overwritten, and that I should stash my changes. OK, I stashed the changes... did the pull, and push the committed changes. But now, I cannot restore the uncommitted changes I was working on.

This is the error:

MyPath/File.cs already exists, no checkout
Could not restore untracked files from stash

For sure I don't yet understand all the concepts of git, they confuse me a bit... maybe I did something wrong.

It would be great if someone could help me solve this... I've been searching google and everything for more than an hour now, and I didn't come to a solution yet.

Help is much appreciated. Thanks!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

It sounds like your stash included an untracked file that was subsequently added to the repo. When you try and check it out, git rightly refuses because it would be overwriting an existing file.

To fix, you could do something like deleting that file (it's okay, it's still in the repo), applying your stash, and then replacing the stashed version of the file with the in-repo version as appropriate.

Edit: It's also possible that the file has only been created in the working tree without having been added to the repo. In this case, don't simply delete the local file, rather:

  1. move it somewhere else
  2. apply the stash
  3. manually merge the two file versions (working tree vs. moved).

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...