如何一次检查所有git存储库的状态? [英] How to check the status of all git repositories at once?

查看:55
本文介绍了如何一次检查所有git存储库的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

为了检查git存储库的状态,可以从存储库的根目录发出 git status .

In order to check the status of git repositores, git status could be issued from the root of a repository.

C:\path\to\git_repositories\git_repo_1>git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

如果目录包含多个目录,例如50个git存储库

If a directory consists of multiple, e.g. 50 git repositories

C:\path\to\git_repositories>dir

 Directory of C:\path\to\git_repositories

  .ssh
  git_repo_1
  ...
  git_repo_50
   0 File(s)
   51 Dir(s)

C:\path\to\git_repositories>git status .
fatal: Not a git repository (or any of the parent directories): .git

都不是

C:\path\to\git_repositories>git status ./.
fatal: Not a git repository (or any of the parent directories): .git

能够检查所有存储库的状态

is able to check the status of all repositories

问题

如何一次检查所有git存储库的状态?

How to check the status of all git repositories at once?

推荐答案

您可以使用 for 循环,该循环会更改到每个目录中,并显示 git status ,然后再返回上:

You could use a for loop that changes into each directory, does git status and then changes back up:

for /f "tokens=*" %a in ('dir /ad /b') do cd %a & git status & cd ..

如果在批处理文件中使用此百分比,则需要将百分比加倍:

You need to double the percentages if you use this in a batch file:

for /f "tokens=*" %%a in ('dir /ad /b') do cd %%a & git status & cd ..

根据Cupcake的建议,您可以改为:

As suggested by Cupcake, you could do this instead:

for /f "tokens=*" %a in ('dir /ad /b') do git --git-dir=%a/.git --work-tree=%a status

这感觉像是一个更强大,更灵活的解决方案(例如,您可以更轻松地对其进行调整,以处理文本文件中存储的路径列表).

This feels like a more robust and flexible solution (e.g. you could adapt it more easily to work with a list of paths stored in a text file).

这篇关于如何一次检查所有git存储库的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆