git submodule init 没有 pull 最新的提交

标签 git git-submodules

我有一个 git 仓库,里面有一个 git 子模块。子模块托管在 bitbucket 上。我想将子模块的本地副本更新为最新提交。我厌倦了“git submodule update”,但它什么也没做。所以我尝试删除子模块文件夹,然后执行“git submodule init”,但它只是提取初始子模块提交,而不是最新提交。

如何让我的本地子模块更新到最新的提交?

最佳答案

Git 正在做它应该做的事情。 git submodule update 会将您的子模块设置为父仓库中当前提交指定的子模块应该位于的位置。通过这种方式,您可以 check out 另一个分支、旧的提交或标记,然后运行 ​​git submodule update,子模块将被设置为该引用所期望的,这样您的整个解决方案就会满足它的依赖性。

你需要做的是:

cd mysubmoduledir
git fetch
git checkout master # or any other branch that you need the latest of
git merge origin/master
cd -  # go back to the top repo
git status # should show that your submodule changed
git add mysubmoduledir
git commit -m "Updated my solution to use latest sub project."

一个较短的版本是:

cd mysubmoduledir
git pull # assumes you are already on the branch you need to be on
cd -
git commit -am "Updated submodule" # assumes you had no other modified files

“更新”这个词对于这个子模块命令来说不是最好的。它的真正意思是“将子模块指向父仓库的提交所期望的提交”。

将子模块更新为不同的提交(不必是最新的)需要您进入该目录,像普通的 git 仓库一样操作它,以便当前提交是您想要的,然后返回并提交此更改在顶级 repo 协议(protocol)中。

关于git submodule init 没有 pull 最新的提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13844996/

相关文章:

Git 获取哈希 A 和 B 之间的更改到工作目录

git - 递归地 git pull 所有的 git 子模块

git - 将上游设置为子模块(或如何将 GitHub 分支作为子模块包含在内)

git - 我可以将 .gitmodules 文件放在子目录中吗?

css - 在 phpstorm 中使用 git 我需要提交才能看到更改吗?

git - 从 Expect 脚本运行 Git 命令失败

git - 使用和 merge git 分支的正确方法

linux - 远程终端和 git 推送是否需要单独的 SSH 公钥?

git - 如何使用 git clone --recursive 加速/并行化 git 子模块的下载?

git - Go:无法在符号链接(symbolic link)中打包