git submodule init 没有提取最新的提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13844996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:53:37  来源:igfitidea点击:

git submodule init not pulling latest commit

gitgit-submodules

提问by levi

I have a git repo with a git submodule inside of it. The submodule is hosted on bitbucket. I want to update my local copy of the submodule to its latest commit. I tired "git submodule update" however that is not doing anything. So I tried deleting the submodule folder and then doing "git submodule init" However it simply pulls the initial submodule commit, not the latest.

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

How can I get my local submodule to update to the latest commit?

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

回答by Adam Dymitruk

Git is doing exactly what it's supposed to be doing. git submodule updatewill set your submodule to what the current commit in the parent repo specifies the submodule should be at. This way you can checkout another branch, older commit or tag, then run git submodule updateand the submodule will be set to what that reference expects so your entire solution will have it's dependencies satisfied.

Git 正在做它应该做的事情。git submodule update将您的子模块设置为父存储库中的当前提交指定子模块应位于的位置。通过这种方式,您可以检出另一个分支、较旧的提交或标记,然后运行git submodule update并且子模块将被设置为该引用所期望的内容,因此您的整个解决方案将满足其依赖关系。

What you need to do is:

你需要做的是:

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

a shorter version is:

较短的版本是:

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

The word "update" is not the best for this submodule command. It really means "point the submodule to the commit that the parent repo's commit expects".

“更新”这个词不是这个子模块命令的最佳选择。它的真正意思是“将子模块指向父存储库的提交期望的提交”。

Updating a submodule to a different commit (doesn't have to be the latest) requires you to cd into that directory, manipulate it like a regular git repo so the current commit is what you want, then go back out and commit this change on the top level repo.

将子模块更新到不同的提交(不必是最新的)需要您 cd 进入该目录,像常规 git repo 一样操作它,以便当前提交是您想要的,然后返回并提交此更改顶级回购。

回答by Saad

Simply try below command after you have added your submodules.

添加子模块后,只需尝试以下命令。

for git v 1.8.x

对于 git v 1.8.x

git submodule update --init --recursive --remote

for v1.7.x:

对于 v1.7.x:

git submodule update --init --recursiveor git pull --recurse-submodules

git submodule update --init --recursive或者 git pull --recurse-submodules

for v1.6.x

对于 v1.6.x

git submodule foreach git pull origin master

to check your git version.

检查您的 git 版本。

git version

回答by qqx

Each git commit which includes a submodule ties to a particular commit within the submodule repository.

每个包含子模块的 git commit 都与子模块存储库中的特定提交相关联。

The git submodule updatecommand is provided to update the checked out version of the submodule to the commit which is recorded for the current version of the parent repository. This may actually be an older version than what you currently have checked out in that submodule, for instance if you are examining an old version of the parent repository which used an older version of the submodule.

git submodule update提供该命令以将子模块的检出版本更新为为父存储库的当前版本记录的提交。这实际上可能比您当前在该子模块中检出的版本更旧,例如,如果您正在检查使用子模块旧版本的父存储库的旧版本。

To get a newer version of the submodule, switch into that directory and update it as you would any other git repository (e.g. pull from the upstream repository). If you make any new commits or you pulled from a repository different from the one you use as the source for the submodule, make sure to push your changes out. After this is done you can return to the parent repository and commit the change to the submodule to record the new submodule commit that you are now using for the submodule in the current version as well as future versions until you make another update.

要获得子模块的更新版本,请切换到该目录并像更新任何其他 git 存储库一样更新它(例如,从上游存储库中拉取)。如果您进行任何新提交或从与用作子模块源的存储库不同的存储库中提取,请确保推送您的更改。完成此操作后,您可以返回父存储库并将更改提交到子模块,以记录您现在用于当前版本和未来版本中的子模块的新子模块提交,直到您进行另一次更新。