git subtree pull 表示工作树有修改,但 git status 表示没有。是什么赋予了?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3623351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git subtree pull says that the working tree has modifications, but git status says it doesn't. What gives?
提问by Sam Deane
If I do this in one of my repositories:
如果我在我的存储库之一中执行此操作:
git subtree pull --prefix=frameworks/AquaticPrime --squash AquaticPrime
I get this:
我明白了:
Working tree has modifications. Cannot add.
If I do this (in the same place, of course):
如果我这样做(当然是在同一个地方):
git status
I get this:
我明白了:
# On branch master
nothing to commit (working directory clean)
I'm not quite sure what's going on here. The git status command implies that I don't have modifications, so I'm assuming that the git subtree pull is referring to modifications in a different branch related to the subtree, but it's not entirely clear.
我不太确定这里发生了什么。git status 命令暗示我没有修改,所以我假设 git subtree pull 是指与子树相关的不同分支中的修改,但并不完全清楚。
Can anyone provide enlightenment?
任何人都可以提供启示吗?
回答by Koryonik
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.
我只是遇到了同样的问题。从 GIT 源来看,当命令git diff-index HEAD
返回结果时会抛出错误,即使git status
说工作树是干净的。
To avoid this error, in my case, I re-checkout the current branch of working tree , and everything seems OK : git checkout <branch>
为了避免这个错误,在我的例子中,我重新检查了 working tree 的当前分支,一切似乎都正常: git checkout <branch>
It's a bit confused, but if someone can explain why ...
有点困惑,但如果有人能解释为什么......
回答by B T
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.
我现在解决了这个问题。在我看来,我的问题是存储库是全新的:我从未向它提交过任何内容。一旦我向 repo 提交了一个文件,我就能够克服这个错误。
However, using the command git subtree add C:\gitTest\repos\subA -d --prefix subA
I got the new error:
但是,使用命令git subtree add C:\gitTest\repos\subA -d --prefix subA
我得到了新错误:
fatal just how do you expect me to merge 0 trees?
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
git subtree add C:\gitTest\repos\subA HEAD -d --prefix subA
And obviously you don't need the -d debug flag.
显然您不需要 -d 调试标志。
回答by Anssi
git reset --hard
fixed it to me
git reset --hard
给我修好了
From git reset --help
从 git reset --help
--hard Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.
--hard 重置索引和工作树。此后对工作树中跟踪文件的任何更改都将被丢弃。
回答by Mikhail T.
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).
- 添加了一个子树;
- 意识到,我错误地添加了它(到错误的目录);
- 用 rm 删除它;
- 尝试再次将其导入(到正确的位置)。
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.
尽管puppet diff
- 正确 - 没有显示任何内容,但git diff-index HEAD
将我刚刚删除的每个文件列为“已删除” - 即使我从未提交(更不用说推送)任何内容。
I believe, this is a bug in git (using 2.7.0 here)... Bug or not, the work-around is to switch to anyother branch (with the usual git checkout ....
) and then back to yours. Hope, this helps someone -- even if not the original asker.
我相信,这是 git 中的一个错误(这里使用 2.7.0)......无论是否有错误,解决方法是切换到任何其他分支(使用通常的git checkout ....
)然后回到你的分支。希望,这可以帮助某人 - 即使不是最初的提问者。
回答by noobar
If you are using Windows, try to use Git Bash instead of PowerShell or cmd.exe. This fixed the problem in my case.
如果您使用的是 Windows,请尝试使用 Git Bash 而不是 PowerShell 或 cmd.exe。这解决了我的问题。
回答by Lars Bilke
Try to pull without --squash
as it is described in this stackoverflow question.
尝试不按此 stackoverflow 问题中的--squash
描述进行拉取。