递归检查git目录更新

时间:2022-12-09 06:30:42

I would like to know if there is a way to determine which sub-folders under a specified directory are git projects. After which, check which of those git projects need updating via 'git fetch' or otherwise.

我想知道是否有办法确定指定目录下的哪些子文件夹是git项目。之后,检查哪些git项目需要通过'git fetch'或其他方式进行更新。

For example, I have a folder called development in my home folder, which holds various projects with about 10% of them using git. Rather than individually check for project updates I would like to be able to run a command which checks for any updates for all of the git folders in the development directory.

例如,我在我的主文件夹中有一个名为development的文件夹,它使用git保存各种项目,其中大约10%。我希望能够运行一个命令,检查开发目录中所有git文件夹的更新,而不是单独检查项目更新。

It would also be nice if it could update non-conflicting projects.

如果它可以更新非冲突项目也会很好。

4 个解决方案

#1


3  

One way to get a list of all Git repos under your current directory is with the following command:

获取当前目录下所有Git repos列表的一种方法是使用以下命令:

find . -name '.git' | xargs -n 1 dirname

You could then feed this into a shell script which runs your command of choice in each repository, either by changing to the directory or by using Git’s --git-dir and --work-tree arguments.

然后,您可以将其提供给shell脚本,该脚本在每个存储库中运行您选择的命令,方法是更改​​为目录或使用Git的--git-dir和--work-tree参数。

#2


3  

Here's a (hacky) one-liner for that:

这是一个(hacky)单线程:

back=`pwd`; for d in `find . -type d -name .git` ; do cd "$d/.."; git pull ; cd $back ; done

#3


1  

Take a look at android's repo. I think there's nothing android specific in it and you will be able to adapt it to your needs.

看看android的回购。我认为它没有特定于Android的东西,你可以根据自己的需要进行调整。

#4


1  

In short:

find . -name .git -execdir git pull -v ';'

You can also create the following script (e.g. update_src.sh):

您还可以创建以下脚本(例如update_src.sh):

#!/bin/sh
# Script to pull all git repositories to the recent version.
ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
find "$ROOT" -name .git -type d -execdir git pull -v ';'

or create a following alias in shell:

或者在shell中创建以下别名:

alias git-pull-all='find $(git rev-parse --show-toplevel 2> /dev/null) -name .git -type d -execdir git pull -v ";"'

or in your ~/.gitconfig.

或者在〜/ .gitconfig中。

#1


3  

One way to get a list of all Git repos under your current directory is with the following command:

获取当前目录下所有Git repos列表的一种方法是使用以下命令:

find . -name '.git' | xargs -n 1 dirname

You could then feed this into a shell script which runs your command of choice in each repository, either by changing to the directory or by using Git’s --git-dir and --work-tree arguments.

然后,您可以将其提供给shell脚本,该脚本在每个存储库中运行您选择的命令,方法是更改​​为目录或使用Git的--git-dir和--work-tree参数。

#2


3  

Here's a (hacky) one-liner for that:

这是一个(hacky)单线程:

back=`pwd`; for d in `find . -type d -name .git` ; do cd "$d/.."; git pull ; cd $back ; done

#3


1  

Take a look at android's repo. I think there's nothing android specific in it and you will be able to adapt it to your needs.

看看android的回购。我认为它没有特定于Android的东西,你可以根据自己的需要进行调整。

#4


1  

In short:

find . -name .git -execdir git pull -v ';'

You can also create the following script (e.g. update_src.sh):

您还可以创建以下脚本(例如update_src.sh):

#!/bin/sh
# Script to pull all git repositories to the recent version.
ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
find "$ROOT" -name .git -type d -execdir git pull -v ';'

or create a following alias in shell:

或者在shell中创建以下别名:

alias git-pull-all='find $(git rev-parse --show-toplevel 2> /dev/null) -name .git -type d -execdir git pull -v ";"'

or in your ~/.gitconfig.

或者在〜/ .gitconfig中。