41

如果我在我的一个存储库中执行此操作:

git subtree pull --prefix=frameworks/AquaticPrime --squash AquaticPrime

我明白了:

Working tree has modifications.  Cannot add.

如果我这样做(当然是在同一个地方):

git status

我明白了:

# On branch master
nothing to commit (working directory clean)

我不太确定这里发生了什么。git status 命令暗示我没有修改,所以我假设 git subtree pull 是指与子树相关的不同分支中的修改,但并不完全清楚。

任何人都可以提供启示吗?

4

7 回答 7

40

我只是有同样的问题。从 GIT 源代码,当命令返回结果时会引发错误git diff-index HEAD,即使git status说工作树是干净的。

为避免此错误,在我的情况下,我重新检查了工作树的当前分支,一切似乎都正常:git checkout <branch>

这有点困惑,但如果有人能解释为什么......

于 2013-09-04T08:07:07.683 回答
17

git reset --hard给我修好了

git reset --help

--hard 重置索引和工作树。此后对工作树中跟踪文件的任何更改都将被丢弃。

于 2016-08-19T11:40:03.297 回答
14

我现在解决了这个问题。在我看来,我的问题是存储库是全新的:我从未向它提交过任何东西。一旦我向 repo 提交了一个文件,我就能够克服这个错误。

但是,使用命令git subtree add C:\gitTest\repos\subA -d --prefix subA我得到了新的错误:

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

搞砸了一分钟后,我发现它需要一个特定的修订版传递给它。所以这个命令似乎成功了:

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

显然你不需要 -d 调试标志。

于 2013-05-28T02:01:48.387 回答
2

我刚遇到这个问题,当我:

  • 添加了一个子树;
  • 意识到,我错误地添加了它(到错误的目录);
  • 用 rm 删除它;
  • 尝试再次将其导入(到正确的位置)。

尽管puppet diff- 正确 - 没有显示任何内容,但git diff-index HEAD我刚刚删除的每个文件都列为“已删除” - 即使我从未提交(更不用说推送)任何内容。

我相信,这是 git 中的一个错误(在此处使用 2.7.0)......无论是否存在错误,解决方法是切换到任何其他分支(使用通常的git checkout ....),然后再回到你的分支。希望这对某人有所帮助——即使不是最初的提问者。

于 2016-04-14T18:51:54.960 回答
0

I had the exact same error. This was occurring on my feature branch. The fix:

  1. Pulled from feature branch remote to local
  2. Pulled from master remote to local
  3. Merged local master to feature branch, committed, and pushed to remote
  4. Ran the `git subtree pull --prefix MySubdirection https://my/repository/url remotebranch --squash

I have no clue why I had to get master and merge to my feature branch, but that solved the issues.

于 2021-05-11T19:30:26.373 回答
0

如果您使用的是 Windows,请尝试使用 Git Bash 而不是 PowerShell 或 cmd.exe。这解决了我的问题。

于 2019-04-22T02:06:39.280 回答
-5

尝试不按此 stackoverflow question--squash中的描述进行拉动。

于 2012-06-11T09:43:22.970 回答