GIT:任何方式提交多个回购?

时间:2011-10-20 19:56:38

标签: git

我知道不建议这样做,但我确实有多个项目的文件夹,我希望保持最新。

是否有一个命令可以查找文件夹中的每个git存储库并发送以下命令..

git add -u 
git add .
git commit -m 'Latest'

所以我可以直接进入某个文件夹,然后运行一个命令让它们全部更新?

这不是子模块问题

4 个答案:

答案 0 :(得分:8)

为什么不使用这样的东西:

#!/bin/bash
for DIR in `ls`;
do
    if [ -d $DIR/.git ];
    then
            echo "updating location: " $DIR;
            cd $DIR
            # your commands here...
            git add -u 
            git add .
            git commit -m 'Latest'

            cd ..
    fi
done

答案 1 :(得分:2)

也许您正在寻找类似mrhomepage)的内容。我用它来一次更新一堆repos,但它可以配置为做你想要的任何东西。它也可以在官方回购中以Ubuntu和Debian包的形式提供。否则你就可以编写一个脚本来为你完成这些工作。

答案 2 :(得分:2)

Disclamer:这是自己的代码。如果您使用或分叉它,我没有经济利益,但它是针对这种情况编写的,也许它有所帮助。 ;)

我写了gitglue。您可以标记存储库并执行基于标记的任意命令。检查this tutorial about gitglue或分叉gitglue on Github.

答案 3 :(得分:0)

我使用bash脚本(在我的.bashrc中)在多个存储库上多次运行同一git命令。 bash对回购位置进行硬编码,但可以轻松更改。多次运行同一命令的问题之一是正确传递带引号的"参数,通常是-m " commit message"

我这样运行这些命令:

mgit commit -a -m "my commit message",其中mgit是我的.bashrc中的别名。

这适用于任何git命令(至少是我每天测试和使用的git命令),例如:

mgit status -unomgit pull

函数解析git参数

此函数可确保所有引号(在-m之后均得到正确处理)

parse_git_args()
{
    git_args=""
    end_comment=""
    for var in "$@"
    do
        if [[ $var == '-m' ]];
        then
            git_args+=" -m \""
            end_comment="\"" 
        else
            git_args+=" $var"
        fi
    done
    git_args+=$end_comment

    echo $git_args
}

在多个存储库上运行相同命令的功能

multiple_git_func()
{
    start=$(pwd)
    git_args=$(parse_git_args $@)
    root=`git rev-parse --show-toplevel` #find the repo from which the command was run

    # go to root apply command and then go to sub repos (hardcoded location wrt root)
    cd $root
    echo "=============================="
    echo "issuing git $git_args on $root"
    eval "git $git_args"


    cd repo2 # repo2 is installed in root, could be anywhere else relative to root
    echo "=============================="
    echo "issuing git $git_args on repo2"
    eval "git $git_args"
   
    #go back to initial folder
    cd $start
}
.bashrc中的

别名

alias mgit=multiple_git_func

相关问题