【发布时间】:2015-10-27 22:59:15
【问题描述】:
我正在使用 TortoiseGit 来维护 git 存储库。我们有一个包含多个子模块的仓库。一切正常,但是当我尝试提取主仓库时,子模块没有更新。我必须一一拉出每个子模块。
tortoise 中是否有一个选项可以仅使用菜单中的一个拉取命令来更新所有子模块中的所有更改以进行 repo?
【问题讨论】:
-
您问的是自动“更新”还是自动“拉取”子模块?
标签: git tortoisegit
我正在使用 TortoiseGit 来维护 git 存储库。我们有一个包含多个子模块的仓库。一切正常,但是当我尝试提取主仓库时,子模块没有更新。我必须一一拉出每个子模块。
tortoise 中是否有一个选项可以仅使用菜单中的一个拉取命令来更新所有子模块中的所有更改以进行 repo?
【问题讨论】:
标签: git tortoisegit
(git 1.8.2 或更高版本)
git 拉
git 子模块更新 --merge --remote
这里是执行任务的 TortoiseGit 的相应屏幕。
【讨论】:
我还可以右键单击作为子模块的文件夹,然后对该文件夹执行普通的 Git 拉取操作。
这仅提取了子模块 - 比上面针对单个子模块的(当然很棒)答案稍微简单一些。
【讨论】:
现在在 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,而不是签入父 repo 的提交:
gitpullallhead.sh:
git submodule foreach git pull origin master
这是他们的工作:
当其他人通过 TortoiseGit 拉下您的项目时,他们将比需要拉出所有子模块更糟糕 - 他们甚至不会配置这些子模块。更糟糕的是,如果他们试图设置它们:
所以,如果他们只是运行 gitsetup.sh,它会处理所有这些 - 它设置每个子模块,拉取它,甚至将特殊的 .ppk(PuTTY 键)配置设置插入每个子模块。适用于任何项目 - 无需每次都进行调整。
gitpullall.sh 会按照你的想法去做,它会去获取所有内容。
所以,严格来说不是 TortoiseGit 解决方案(不存在),但仍然足够方便。
正如那些脚本中的 cmets 很可能证明的那样,我不是 Bash 专业人士,并且显然将它们破解在一起。我欢迎改进建议,尤其是在最明显的地方。但我向您保证,它们不仅可以工作,而且可以在我们的多个项目中工作,其中有许多子模块存储在多个目录级别。
旧答案:
类似:
for module in a b c d; do cd $module; git pull; cd..; done
【讨论】: