我知道这不是推荐的做法,但是我有一些包含多个项目的文件夹,我想让它们保持最新。
有没有一条命令可以查找文件夹中的每个git存储库并发送以下命令..
git add -u
git add .
git commit -m 'Latest'
所以我只需要进入某个文件夹,然后运行一个命令来更新它们所有的内容吗?
这不是有关子模块的问题。
我知道这不是推荐的做法,但是我有一些包含多个项目的文件夹,我想让它们保持最新。
有没有一条命令可以查找文件夹中的每个git存储库并发送以下命令..
git add -u
git add .
git commit -m 'Latest'
所以我只需要进入某个文件夹,然后运行一个命令来更新它们所有的内容吗?
这不是有关子模块的问题。
#!/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
/bin/bash
吗?好的,我知道了...我猜你也必须告诉Windows如何执行脚本或从mingw shell中执行它,对吧? - Scolytusmr
的东西(主页)。我使用它来一次更新一堆仓库,但也可以配置为执行任何你想要的任务。它也作为Ubuntu和Debian官方仓库中的软件包提供。否则,你可以编写一个脚本来完成你想要的任务。.bashrc
中)来在多个存储库上运行相同的git命令。bash硬编码了存储库位置,但很容易更改。运行多次相同命令的问题之一是正确传递带引号的"
参数,通常是-m "commit message"
我像这样运行这些命令:
mgit commit -a -m "my commit message"
其中mgit是我.bashrc中的别名。mgit status -uno
,mgit 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
}
alias mgit=multiple_git_func