有办法自动有git子模块更新(或最好是git子模块更新——init调用每当git拉?

寻找一个git配置设置,或一个git别名来帮助这一点。


当前回答

Git配置——全局别名。pullall”!Git pull && Git子模块更新——init——递归

如果你想把参数传递给git pull,那么使用下面的代码:

git config --global alias.pullall '!f(){ git pull "$@" && git submodule update --init --recursive; }; f'

其他回答

从Git 2.14开始,你可以使用Git的pull - recursive -submodules(和你喜欢的别名)。

从Git 2.15开始,你可以设置submodule。递归为true以启用所需的行为。

你可以通过运行:

git config --global submodule.recurse true

Git配置——全局别名。pullall”!Git pull && Git子模块更新——init——递归

如果你想把参数传递给git pull,那么使用下面的代码:

git config --global alias.pullall '!f(){ git pull "$@" && git submodule update --init --recursive; }; f'

我如何能够获得子模块和嵌套子模块更新的唯一方法:

git submodule update --remote --merge --recursive; git submodule foreach --recursive "(git add .; git commit -m 'SubmoduleSync'; git push; git pull;);" git add .; git commit -m 'SubmodulesSynced'; git push; git pull;

由于括号,我努力通过终端创建别名,所以我必须手动将此添加到.gitconfig全局:

[alias] supdate = "!git submodule update --remote --merge --recursive; git submodule foreach --recursive '(git add .; git commit -m 'SubmoduleSync'; git push; git pull;);' git add .; git commit -m 'SubmodulesSynced'; git push; git pull;"

对于如何自动运行命令或别名有什么建议吗?

Kevin Ballard建议的别名是一个非常好的解决方案。只是抛出另一个选项,你也可以使用post-merge钩子,它只运行git子模块update[——init]。

您可以为git命令创建一个别名,以自动处理子模块更新。将以下内容添加到.bashrc中

# make git submodules usable
#   This overwrites the 'git' command with modifications where necessary, and
#   calls the original otherwise
git() {
    if [[ $@ == clone* ]]; then
        gitargs=$(echo "$@" | cut -c6-)
        command git clone --recursive $gitargs
    elif [[ $@ == pull* ]]; then
        command git "$@" && git submodule update --init --recursive
    elif [[ $@ == checkout* ]]; then
        command git "$@" && git submodule update --init --recursive
    else
        command git "$@"
    fi
}