如何使用“git submodule”检查子模块的特定版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10914022/
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
How do I check out a specific version of a submodule using 'git submodule'?
提问by joemaller
How would I go about adding a Git submodule for a specific tag or commit?
我将如何为特定标签或提交添加 Git 子模块?
回答by joemaller
Submodule repositories stay in a detached HEAD state pointing to a specific commit. Changing that commit simply involves checking out a different tag or commit then adding the change to the parent repository.
子模块存储库保持指向特定提交的分离 HEAD 状态。更改提交只涉及签出不同的标签或提交,然后将更改添加到父存储库。
$ cd submodule
$ git checkout v2.0
Previous HEAD position was 5c1277e... bumped version to 2.0.5
HEAD is now at f0a0036... version 2.0
git-status
on the parent repository will now report a dirty tree:
git-status
在父存储库上现在将报告一个脏树:
# On branch dev [...]
#
# modified: submodule (new commits)
Add the submodule directory and commit to store the new pointer.
添加子模块目录并提交以存储新指针。
回答by fsenart
Step 1: Add the submodule
git submodule add git://some_repository.git some_repository
Step 2: Fix the submodule to a particular commit
By default the new submodule will be tracking HEAD of the master branch, but it will NOT be updated as you update your primary repository. In order to change the submodule to track a particular commit or different branch, change directory to the submodule folder and switch branches just like you would in a normal repository.
git checkout -b some_branch origin/some_branch
Now the submodule is fixed on the development branch instead of HEAD of master.
第一步:添加子模块
git submodule add git://some_repository.git some_repository
第 2 步:将子模块修复到特定提交
默认情况下,新子模块将跟踪主分支的 HEAD,但不会在您更新主存储库时更新。为了更改子模块以跟踪特定提交或不同分支,请将目录更改为子模块文件夹并切换分支,就像在普通存储库中一样。
git checkout -b some_branch origin/some_branch
现在子模块固定在开发分支上,而不是 master 的 HEAD。
From Two Guys Arguing — Tie Git Submodules to a Particular Commit or Branch .