检查多个存储库中是否需要推送/提交

Gab*_*ert 2 git

我的计算机上有 140 个 git 存储库,每周可以处理其中 10-15 个。有没有办法知道是否忘记提交/推送我的一个项目?

这些存储库都位于同一位置:“C:/Projects”。

输出会是这样的

  1. C:/Projects/lib1 -> 需要提交和推送
  2. C:/Projects/lib6 -> 需要提交和推送
  3. C:/Projects/lib11 -> 需要提交和推送

谢谢你!

gah*_*ooa 5

一个非常简单的 python 脚本就可以为你做到这一点:

import glob
import subprocess
import os
from os.path import dirname


dirs = glob.glob('c:/projects/*/.git')

for dir in dirs:
  dir = dirname(dir)   #strip .git off the end

  os.chdir(dir)

  status = subprocess.check_call(('git', 'status'))

  # Check status, and potentially do this

  subprocess.check_call(('git', 'add', '-A'))
  subprocess.check_call(('git', 'commit', '-m', 'Automatic Commit'))
  subprocess.check_call(('git', 'push', 'origin', 'HEAD'))
Run Code Online (Sandbox Code Playgroud)

差不多就是这样了。你需要在你的计算机上安装 python,然后对其进行调整。