为什么对以下文件的本地更改会被合并覆盖?

Why local changes to the following files would be overwritten by merge?

我在不同的地方对 Makefile 进行了更改。

为什么我还是报错?

$ git stash pop
error: Your local changes to the following files would be overwritten by merge:
    Makefile
Please commit your changes or stash them before you merge.
Aborting
The stash entry is kept in case you need it again.

我的更改没有交叉。所以我希望它们应该毫无问题地合并。

存在技术问题,阻止 git stash pop 像其他命令一样自由使用索引(因为它实际上修改了索引本身),并避免围绕 stash apply 机制的复杂逻辑,至此,git stash pop 只是拒绝对“不干净”的文件应用更改。


解决此问题的简单方法是使用所述文件创建提交:

git add Makefile
git commit -m "wip"
git stash pop

# ... fix stuff if needed ...

# after stash application : you can jump one commit backwards
git reset --soft HEAD^   # if you want to keep stuff in the index
git reset HEAD^          # if you can reset the index too