2021年2月23日 星期二

[Git 常見問題] Easy way to pull latest of all git submodules

 Source From Here

Question
We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.

Does git have a built-in command to do this? If not, how about a Windows batch file or similar that can do it?

HowTo
If it's the first time you check-out a repo you need to use --init first:
// Add a submodule covid19_data
# git submodule add https://github.com/johnklee/covid19_data.git
# git submodule update --init --recursive

For Git 1.8.2 or above, the option --remote was added to support updating to latest tips of remote branches:
// Confirm this will work in git version 2.27.0
# git submodule update --recursive --remote
...
Submodule path 'covid19_data': checked out '76db104ffdb4f0ffd9aaa2b7fddd2a969e6bd199'

This has the added benefit of respecting any "non-default" branches specified in the .gitmodules or .git/config files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).

For Git 1.7.3 or above you can use (but the below gotchas around what update does still apply):
# git submodule update --recursive

or:
# git pull --recurse-submodules

if you want to pull your submodules to latest commits instead of the current commit the repo points to.

See git-submodule(1) for details

Supplement
Git 文章收集 - Git Submodule 介紹與使用




沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...