使用 TortoiseGit 拉取 git 子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16058917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:26:23  来源:igfitidea点击:

Pulling git submodules with TortoiseGit

gittortoisegit

提问by David Marks

I'm using TortoiseGit to maintain git repository. We have one repo with multiple submodules in each. Everything works fine but when I'm trying to pull main repo, submodules aren't updating. I must pull every submodule one by one.

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

Is there an option in tortoise to use only one pull command from menu to update all changes in all submodules for repo?

tortoise 中是否有一个选项可以只使用菜单中的一个 pull 命令来更新所有子模块中的所有更改以进行回购?

回答by linquize

(git 1.8.2 or later)

(git 1.8.2 或更高版本)

  1. git pull

  2. git submodule update --merge --remote

  1. git 子模块更新 --merge --remote

Here are the corresponding screens of TortoiseGit to perform the task.

下面是 TortoiseGit 执行任务的相应屏幕。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Chris Moschini

Update

更新

There is now a way to do this in TortoiseGit, which the other answer covers; old script approach that can be useful for automation scripts below.

现在有一种方法可以在 TortoiseGit 中执行此操作,另一个答案涵盖了该方法;对下面的自动化脚本有用的旧脚本方法。

Old Edit

旧版

There is no current way to do this in TortoiseGit, although I've found the author is very responsive to good ideas if you submit them as clear Feature Requests. Here's how I cope with this issue:

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

In every new project with submodules, I dump the following 2 scripts into the root:

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

gitsetup.sh

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.\]\)/\n$puttyline/" $file
    fi
done

gitpullall.sh

gitpullall.sh

#!/bin/bash -v
git pull --recurse-submodules
git submodule update --recursive

or if you'd prefer to fetch HEAD on your submodules, not the commit the parent repo was checked in with:

或者,如果您更喜欢在子模块上获取 HEAD,而不是使用以下方式检入父存储库的提交:

gitpullallhead.sh:

gitpullallhead.sh:

git submodule foreach git pull origin master

Here's what they do:

以下是他们所做的:

When someone else pulls your project down via TortoiseGit, they're going to have worse than needing to pull all submodules - they won't even have those submodules configured. Worse, if they attempted to set them up:

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

  1. TortoiseGit is just going to get in their way - it doesn't really have anything to cope with this problem yet.
  2. They'll use the command line, which will point each submodule at its repo but not associate it with your Tortoise/PuTTY key like a normal Pull would.
  1. TortoiseGit 只会妨碍他们 - 它实际上还没有任何东西可以解决这个问题。
  2. 他们将使用命令行,该命令行会将每个子模块指向其存储库,但不会像普通的 Pull 那样将其与您的 Tortoise/PuTTY 键相关联。

So, if they just run gitsetup.sh, it takes care of all of that - it sets up each submodule, pulls it, and even inserts the special .ppk (PuTTY key) config setting into each one. Works in any project - no need to tweak it each time.

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

gitpullall.sh does just what you think, it goes and fetches everything.

gitpullall.sh 会按照你的想法去做,它会去获取所有东西。

So, not strictly a TortoiseGit solution (that doesn't exist), but still convenient enough.

因此,严格来说不是 TortoiseGit 解决方案(不存在),但仍然足够方便。

As is likely evidenced by the comments in those scripts, I am no Bash professional and clearly hacked them together. I welcome suggestions for improvements especially in the most obvious places. But I assure you they not only work but work across several of our projects with numerous submodules stored at several directory levels.

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

Old answer:

旧答案:

Something like:

就像是:

for module in a b c d; do cd $module; git pull; cd..; done

回答by Ian Grainger

I was also able to just right-click on the folder that was the submodule and do a normal Git Pull on that folder.

我还可以右键单击作为子模块的文件夹,然后对该文件夹执行正常的 Git Pull。

This pulled just the submodule - so slightly simpler than the (admittedly great) answer above for a single submodule.

这仅拉取了子模块 - 比上面单个子模块的(无可否认的好)答案稍微简单。