git 子模块更新与 git 子模块同步
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45678862/
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
git submodule update vs git submodule sync
提问by Benjamin Leinweber
The git
documentation doesn't make it at all clear what the difference is between a git submodule update
and a git submodule sync
is. I'm also not finding any help out on the web. Can someone help me out with what the difference is here?
该git
文档根本没有说明 agit submodule update
和 a之间的区别是什么git submodule sync
。我也没有在网上找到任何帮助。有人可以帮我弄清楚这里有什么区别吗?
update
Update the registered submodules to match what the superproject expects
by cloning missing submodules and updating the working tree of the
submodules. The "updating" can be done in several ways depending on
command line options and the value of submodule.<name>.update
configuration variable.
-
——
sync
Synchronizes submodules' remote URL configuration setting to the value
specified in .gitmodules. It will only affect those submodules which
already have a URL entry in .git/config (that is the case when they are
initialized or freshly added). This is useful when submodule URLs
change upstream and you need to update your local repositories
accordingly.
For reference, I'm using the git client version 2.11.0
作为参考,我使用的是 git 客户端版本 2.11.0
回答by o11c
update
is basically doing git pull
in each submodule (except without a branch, since the main repo specifies a commit directly).
update
基本上是git pull
在每个子模块中做的(除了没有分支,因为主 repo 直接指定了一个提交)。
The tricky one is sync
. Imagine you clone a project with submodules, then later the upstream project changesone of the submodules to point to a different URL.
棘手的是sync
。想象一下,您克隆了一个带有子模块的项目,然后上游项目将其中一个子模块更改为指向不同的 URL。
Your local copy of the submodule will still point to the old URL, since git neverallows remote repositories to force a change to local configuration. You need to run git submodule sync
to apply the remote repo's configuration to your local submodule repos.
您的子模块的本地副本仍将指向旧 URL,因为 git从不允许远程存储库强制更改本地配置。您需要运行git submodule sync
以将远程存储库的配置应用于本地子模块存储库。
Note also that, if you are making changesto the submodules, you might wantthe URLs to mismatch even if the upstream never changed them ... but using multipleremote URLs is probably a better idea for that case.
另请注意,如果您对子模块进行更改,即使上游从未更改过,您也可能希望URL 不匹配……但在这种情况下,使用多个远程 URL 可能是一个更好的主意。
回答by larsks
git submodule update
updates the contentsof the submodules. It is effectively running a "git fetch" and "git checkout" in each of your submodules.
git submodule update
更新子模块的内容。它在您的每个子模块中有效地运行“git fetch”和“git checkout”。
git submodule sync
updates the metadataabout a submodule to reflect changes in the submodule URL. It re-synchronizes the information in .git/config
with the information in .gitmodules
.
git submodule sync
更新有关子模块的元数据以反映子模块 URL 中的更改。它将 中的信息.git/config
与 中的信息重新同步.gitmodules
。