无法弹出git stash,'您对以下文件的本地更改将被合并覆盖'

时间:2013-11-12 18:55:04

标签: git git-stash

所以我有大量的更改和一些未跟踪的文件。我需要调整一些内容,因此我使用git stash -u,修改了一些内容,提交了这些更改,推送它们,然后尝试git stash pop

因为我修改了几个我藏匿的文件,所以收到了以下消息:

error: Your local changes to the following files would be overwritten by merge:
    file_1.py
    file_2.py
Please, commit your changes or stash them before you can merge.
Aborting

这看起来很奇怪,我已经提交了所有新的更改,当我运行命令时,我的结账很干净。

似乎git stash pop操作取消了我的一半更改和未跟踪文件,但如果我再次尝试git stash pop,我会得到如下输出:

some_file.html already exists, no checkout
some_other_file.html already exists, no checkout
yet_another_file.html already exists, no checkout
Could not restore untracked files from stash

git stash show仍然显示了我的隐藏更改列表,但我对我现在所做的事情感到茫然。

我怎样才能让自己失去理智?

4 个答案:

答案 0 :(得分:51)

对于那些 未提交作品的人,并希望在不丢失该作品的情况下弹出他们的藏品,这是一种方式(感谢@iFreilicht):

  1. 暂时暂停任何未提交的更改:

    git add -u .
    
  2. 现在你可以申请你的存储而不用git抱怨(希望如此):

    git stash pop
    
  3. 现在取消所有内容,但保留现在的文件:

    git reset
    

答案 1 :(得分:21)

我解决了这个问题,我认为这肯定是某种错误,因为我的工作目录很干净且最新。

我跑了git checkout .,之后git stash apply工作正常,我得到的一切都没有问题。我有兴趣弄清楚实际上导致它失败的原因。

答案 2 :(得分:1)

使用-u创建的藏匿文件需要在apply之前清除未跟踪的文件,而pop只是apply + {{1} })。

出于普遍的偏执,我drop安全地将未跟踪的文件mv,然后git stash apply,仔细检查所有内容,git stash drop一旦我确定我的一切正确。 : - )

答案 3 :(得分:0)

这些解决方案都不适合我。我正在使用git stash index命令来还原特定的存储ID。因此,我最终将本地更改提交到本地存储库。然后git stash index对我有用。最后,我使用git reset(保留更改)回滚了提交。问题解决了。