使用TortoiseGit拉动git子模块

Dav*_*rks 16 git tortoisegit

我正在使用TortoiseGit来维护git存储库.我们有一个repo,每个repo有多个子模块.一切正常,但是当我试图拉回主回购时,子模块没有更新.我必须逐个拉出每个子模块.

在龟中是否有一个选项,只使用菜单中的一个pull命令来更新repo的所有子模块中的所有更改?

lin*_*ize 28

(git 1.8.2或更高版本)

  1. git pull

  2. git submodule update --merge --remote

以下是TortoiseGit执行任务的相应屏幕.

在此输入图像描述

在此输入图像描述

在此输入图像描述


Chr*_*ini 2

更新

现在在 TortoiseGit 中有一种方法可以做到这一点,另一个答案涵盖了这一点;旧的脚本方法对于下面的自动化脚本很有用。

旧编辑

目前在 TortoiseGit 中没有办法做到这一点,尽管我发现如果您将好的想法作为明确的功能请求提交,作者会对它们非常敏感。以下是我处理这个问题的方法:

在每个带有子模块的新项目中,我将以下 2 个脚本转储到根目录中:

gitsetup.sh

#!/bin/bash
# git built-in
echo "Setting up submodules"
git submodule update --init

echo "Setting up submodules for TortoiseGit/Putty"
# 1) Find the puttykeyfile line, like
#         puttykeyfile = C:\\Users...\\.ssh\\PuTTY.ppk
# 
# in .git/config

# pass to sed to double-escape all backslashes (Windows problem) - that way
# it doesn't become an issue when we use it in sed
puttyline="$(grep puttykeyfile .git/config | sed 's/\\/\\\\/g')"

# 2) Search for .git/modules/*/config

files=$(find .git/modules -type f -name config)

# 3) Find [remote "origin"] 
# 4) Insert line (entire puttykeyfile line we picked up earlier)

echo 'Inserting missing TortoiseGit .ppk into submodules:'

for file in $files
do
    # -q says don't print the grep results, just return 0 or 1
    if grep -q putty $file
    then
        # I have no idea how to just say if not grep, so screw it here's an empty then
        /dev/null
    else
        echo $file
        # -i means overwrite the file rather than printing the result to
        # stdout
        sed -i "s/\(\[remote .origin.\]\)/\1\n$puttyline/" $file
    fi
done
Run Code Online (Sandbox Code Playgroud)

gitpullall.sh

#!/bin/bash -v
git pull --recurse-submodules
git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)

或者,如果您希望在子模块上获取 HEAD,而不是签入父存储库的提交:

gitpullallhead.sh:

git submodule foreach git pull origin master
Run Code Online (Sandbox Code Playgroud)

他们是这样做的:

当其他人通过 TortoiseGit 拉取你的项目时,他们会比需要拉取所有子模块更糟糕 - 他们甚至不会配置这些子模块。更糟糕的是,如果他们试图设置它们:

  1. TortoiseGit 只会妨碍他们——它还没有任何办法来解决这个问题。
  2. 他们将使用命令行,该命令行会将每个子模块指向其存储库,但不会像普通 Pull 那样将其与您的 Tortoise/PuTTY 密钥关联起来。

因此,如果他们只是运行 gitsetup.sh,它会处理所有这些 - 它设置每个子模块,拉出它,甚至将特殊的 .ppk(PuTTY 键)配置设置插入每个子模块。适用于任何项目 - 无需每次都进行调整。

gitpullall.sh 就像你想的那样,它会获取所有内容。

所以,严格来说,这不是一个 TortoiseGit 解决方案(不存在),但仍然足够方便。

正如这些脚本中的评论所证明的那样,我不是 Bash 专业人士,并且显然将它们组合在一起。我欢迎提出改进建议,尤其是在最明显的地方。但我向您保证,它们不仅可以工作,而且可以跨我们的几个项目工作,其中有许多子模块存储在多个目录级别。

旧答案:

就像是:

for module in a b c d; do cd $module; git pull; cd..; done
Run Code Online (Sandbox Code Playgroud)