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

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

git submodule update vs git submodule sync

gitgit-submodules

提问by Benjamin Leinweber

The gitdocumentation doesn't make it at all clear what the difference is between a git submodule updateand a git submodule syncis. 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

updateis basically doing git pullin 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 syncto 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 updateupdates 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 syncupdates the metadataabout a submodule to reflect changes in the submodule URL. It re-synchronizes the information in .git/configwith the information in .gitmodules.

git submodule sync更新有关子模块的元数据以反映子模块 URL 中的更改。它将 中的信息.git/config与 中的信息重新同步.gitmodules