git subtree pull 表示工作树已修改,但 git status 表示没有。什么给?

发布于 2024-09-17 07:30:19 字数 492 浏览 4 评论 0原文

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

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 指的是与子树相关的不同分支中的修改,但并不完全清楚。

有人可以提供启示吗?

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.

Can anyone provide enlightenment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

柳絮泡泡 2024-09-24 07:30:19

我刚刚遇到了同样的问题。
从 GIT 源代码来看,当命令 git diff-index HEAD 返回结果时,即使 git status 表示工作树是干净的,也会引发错误。

为了避免这个错误,在我的例子中,我重新签出工作树的当前分支,一切似乎都正常: git checkout

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

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 ...

还如梦归 2024-09-24 07:30:19

git reset --hard 将其修复给我

来自 git reset --help

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

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.

暖阳 2024-09-24 07:30:19

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

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

致命的你期望我如何合并 0 棵树? 搞乱了

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

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

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

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.

坏尐絯℡ 2024-09-24 07:30:19

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

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

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

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

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.

梦醒灬来后我 2024-09-24 07:30:19

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

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

痴者 2024-09-24 07:30:19

我有完全相同的错误。这发生在我的功能分支上。修复:

  1. 从远程功能分支拉取到本地
  2. 从远程主控拉取到本地
  3. 将本地主控合并到功能分支,提交并推送到远程
  4. 运行 `git subtree pull --prefix MySubdirection https://my/repository/url remotebranch - -squash

我不知道为什么我必须掌握并合并到我的功能分支,但这解决了问题。

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.

疯到世界奔溃 2024-09-24 07:30:19

我在使用 SourceTree 时遇到了这个问题。问题是当我设置子树时,我选择了一个现有文件夹。有一个警告,但我忽略了它。再次设置子树,但输入新的文件夹名称(尚不存在)解决了该问题。

I had this problem with SourceTree. The problem was when I set up the subtree, I was selecting an existing folder. There was a warning but I ignored it. Setting up the subtree again but typing in a new folder name (one that doesn't exist yet) fixed the issue.

闻呓 2024-09-24 07:30:19

在尝试执行修改存储库的 Git 命令(例如 git subtree add)之前,请确保已提交对本地 Git 存储库所做的所有更改。这将避免由于开放提交而可能出现的任何问题

Ensure that all changes made to your local Git repository have been committed before attempting to execute Git commands that modify your repository, such as git subtree add. This will avoid any issues that might occur due to open commit

长途伴 2024-09-24 07:30:19

我这样做是作为项目中的第一次提交,很奇怪(git 分支)没有显示任何内容。我做了一个 tmp 提交,然后它就起作用了

I was doing this as the first commit in a project and it was weird (git branch) showed nothing. I made a tmp commit and then it worked

北音执念 2024-09-24 07:30:19

尝试在不使用 --squash 的情况下进行拉取,如此 stackoverflow 问题中所述。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文