我正在使用TortoiseGit来维护git仓库。我们有一个repo,其中每个子模块都有多个。一切运作良好,但当我尝试拉取主仓库时,子模块没有更新。我必须一个一个地拉取每个子模块。
在tortoise中是否有选项可以只使用菜单中的一个拉取命令,以更新所有子模块中的所有更改?
我正在使用TortoiseGit来维护git仓库。我们有一个repo,其中每个子模块都有多个。一切运作良好,但当我尝试拉取主仓库时,子模块没有更新。我必须一个一个地拉取每个子模块。
在tortoise中是否有选项可以只使用菜单中的一个拉取命令,以更新所有子模块中的所有更改?
(Git 1.8.2 或更高版本)
执行git pull
执行git submodule update --merge --remote
以下是TortoiseGit对应的操作截图。
现在在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
gitpullall.sh
#!/bin/bash -v
git pull --recurse-submodules
git submodule update --recursive
如果您希望获取子模块上的HEAD,而不是父存储库检入的提交:
gitpullallhead.sh:
git submodule foreach git pull origin master
for module in a b c d; do cd $module; git pull; cd..; done
我还可以右键点击子模块所在的文件夹,并在该文件夹上执行常规的Git Pull操作。
这只拉取了子模块 - 所以相对于上面的答案来说稍微简单一些(尽管那个答案也很好用)。