首页 > 解决方案 > 递归检查是否有 git 签出文件

问题描述

我的所有项目都在一个名为 c:\Projects 的文件夹中。它们都是托管在 Bitbucket 上的 git 项目,我希望遍历所有这些文件夹并检查是否有需要推送的修改文件。有没有办法通过 PowerShell / cmd 行来做到这一点?

谢谢

标签: gitpowershellcmd

解决方案


我建议你使用简单的脚本:

$directory = "C:\users\turek\source\my_git_repos";
dir $directory -Directory | ForEach-Object { 
    cd $_.FullName;
    git status; 
};

或者,更复杂的版本,它不进入不是 git 存储库的目录:

$directory = "C:\users\turek\source\my_git_repos";
# gets all subdirectories and loops through them
dir $directory -Directory | ForEach-Object {
    # if the directory is git repo, then check the status
    if ( Test-Path -Path "$($_.FullName)\.git" ) {
        # switches directory
        cd $_.FullName;
        # gets GIT repo status 
        git status; 
    }
};

推荐阅读