我有一个带有子模块的父项目(没有嵌套的子模块)。子模块有一个新的提交(我们称它为 new-sha
),父模块在远程 repo 中引用该提交(我可以在查看时看到 submodule @new-sha
网络浏览器中的 repo )。
我已经 pull 了父项目,它也引用了工作目录中的正确提交,如 git show
输出所示:
--- a/submodule
--- b/submodule
@@ -1 +1 @@
-Subproject commit old-sha
+Subproject commit new-sha
即父项目中的最新提交已将子模块更改为 new-sha
。但是,git submodule update
和 git pull --recurse-submodules
都没有更新子模块中的 new-sha
,它们总是检查 老沙
.
为什么,以及如何解决?
git 版本 2.21.0.windows.1
一些附加信息:子模块在本地有sha-new
,但它的HEAD卡在sha-old
。
sha-new
直接派生自 sha-old
,这是最后 3 次提交,也许这可以提供线索:
sha-new == the top of submodule's branch used by parent project
sha-old == HEAD
sha-xyz == origin/HEAD
origin/HEAD
行让我担心。即使在手动 pull 子模块后 (cd submodule; git pull origin branch-name:branch-name
) origin/HEAD
仍然停留在倒数第三次提交。
最佳答案
您需要确保新提交已推送到子模块远程存储库。 (.gitmodules
URL line 中列出的那个)
然后你需要在你的主要父仓库本地克隆中做一个 git status,检查它是最新的 master
分支和 git ls-tree
does show the right submodule root tree commit .
OP me76添加 in the comments :
I "solved" it differently.
I had to do some changes in the submodule, so I manually switched to the right commit, did and committed the changes in submodule, and committed the submodule in the parent project.
This finally updated the reference to submodule.
那是因为这样做会强制主存储库更新 gitlink (special entry in the index)引用子模块主文件夹树的新提交。
推送将发布新的 gitlink 提交。
OP 还提到了 this thread :
The person had (apparently conflicting) version of submodule in the index (
git ls-files --stage | grep 160000
).After removing it from index (
git rm --cached
) and re-adding it withgit submodule add
, I was finally able to update the submodule from the parent project.
注意:git rm --cached asubmoduleFolder
不能以“/
”结尾:您正在删除一个 gitlink(索引中的“160000”特殊条目) .不是文件夹。
https://stackoverflow.com/questions/56371564/
相关文章:
docker - 无法使用 docker login --password-stdin
google-drive-api - 从 Google Drive "Computers"获取文件到
reactjs - 我们如何在使用 react 最终形式时在组件中设置状态
node.js - 在 Nexus 中获取最新版本的 Node 包
python - 是否可以在 Snakemake 中有一个可选的输出文件?
python-3.x - 如何在 Python 中创建具有每个变量值之间差距的堆积条形图
google-chrome - 本地主机 Web 应用程序访问远程 API 时未设置 Cookie