git subtree pull says that the working tree has modifications, but git status says it doesn't. What gives?

痴心易碎 提交于 2019-11-30 16:58:19

I just had the same problem. From GIT source, error is thrown when command git diff-index HEAD returns result, even if git status says working tree is clean.

To avoid this error, in my case, I re-checkout the current branch of working tree , and everything seems OK : git checkout <branch>

It's a bit confused, but if someone can explain why ...

I got around this now. My problem seemed to me that the repository was brand new: I had never committed anything to it. Once I committed a file to the repo, I was able to move past this error.

However, using the command git subtree add C:\gitTest\repos\subA -d --prefix subA I got the new error:

fatal just how do you expect me to merge 0 trees?

After messing around for a minute, I figured out it requires that a specific revision be passed to it. So this command seems to have succeeded:

git subtree add C:\gitTest\repos\subA HEAD -d --prefix subA

And obviously you don't need the -d debug flag.

git reset --hard fixed it to me

From git reset --help

--hard Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.

I just had this problem, when I:

  • added a subtree;
  • realized, I added it incorrectly (to a wrong directory);
  • removed it with rm;
  • tried to import it again (to the correct place).

Although puppet diff was -- correctly -- showing nothing, the git diff-index HEAD listed each of the files I just deleted as "deleted" -- even though I never commit-ed (much less push-ed) anything.

I believe, this is a bug in git (using 2.7.0 here)... Bug or not, the work-around is to switch to any other branch (with the usual git checkout ....) and then back to yours. Hope, this helps someone -- even if not the original asker.

If you are using Windows, try to use Git Bash instead of PowerShell or cmd.exe. This fixed the problem in my case.

Lars Bilke

Try to pull without --squash as it is described in this stackoverflow question.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!