git - Windows 上的 GitHub Desktop 上的子模块总是出现 checkout 错误

标签 git github git-submodules

我有一个包含几个分支的 repo 协议(protocol)。在其中一个上,我删除了一个实际上不属于 repo 的目录,并将其作为 git 子模块添加回来。

我就是这样做的:

  1. 克隆代码库
  2. 切换到 GitHub Desktop 中子模块所在的分支
  3. git 子模块初始化
  4. 到目前为止,我可以切换分支(在有子模块和没有子模块的分支之间没有任何问题)。
  5. git submodule update 最终得到子模块的“内容”

所以一切正常,直到我尝试在 GitHub Desktop 中切换分支(切换到另一个没有任何 git 子模块的分支)。如果我这样做,我会收到一个 checkout 错误,声称我有未提交的更改: GitHubCheckoutIssue

Failed to checkout the branch

The following files in your working directory would be overwritten by a checkout: [...] Please commit your changes before you can switch branches.

然而正如我所说我没有改变任何东西——我唯一做的就是更新我的子模块。

git status 显示一切正常:

$ git status
On branch patch-submodule
Your branch is up-to-date with 'origin/patch-submodule'.

nothing to commit, working directory clean

当我deinit 我的子模块时,我也可以再次切换分支。

那么这里有什么问题呢? 我该如何防止或解决此错误?

最佳答案

感谢 GitHub 的支持,我终于得到了非常有用的回复。

特别是他们把我带到了Replaced third party code with git submodules, now I can't switch branches这恰好描述了我的问题 - 除了一个区别:我确实使用了 GitHub GUI 而不是控制台。

并且有链接 to git-scm很好地解释了这一点:

Switching branches with submodules in them can also be tricky. If you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you still have the submodule directory as an untracked directory[.]

[...] You have to either move it out of the way or remove it, in which case you have to clone it again when you switch back—and you may lose local changes or branches that you didn’t push up.

这基本上就是我的错误消息的全部含义。

关于git - Windows 上的 GitHub Desktop 上的子模块总是出现 checkout 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639955/

相关文章:

git - git 和二进制文件的自定义差异

git - 防止 git secret 配置文件被推送

git push 内存不足,malloc 失败

github - 是否可以在拉取请求(Github)中更改其他人的代码?

git - 将 Git 子模块转换为子树后 merge 错误

git - `git rebase --skip` 在 rebase 过程中究竟跳过了什么?

git - 如何让 GitHub 上不受信任的贡献者参与进来?

node.js - 如何使用私有(private) Github 存储库作为 npm 依赖项

git - 为什么 git 无法为给定的提交获取特定的有效子模块以及如何修复它?

git - 在 GIT 中,项目混合新旧版本子组件的最佳方式是什么?