2014-02-06 74 views
1

我有一堆巨大的,可怕的一堆git存储库,包括我自己的和几个客户端,散布在一组目录中(我工作的其他几个开发人员都拥有同样的问题)。我想编写一个脚本,我和他们可以运行它将遍历一组目录并告诉我们哪些脚本具有未提交的更改。可悲的是,我在那里看到的大多数示例都是使用bash来实现的,这些bash可能不适用于所有机器(我们是windows商店)。有没有办法在PowerShell或普通的旧批处理文件中做到这一点?如何检查窗口中未提交的git存储库

回答

3

这里有一个快速“东经脏PowerShell脚本:

$fn = $env:temp\gitStat.txt 
$dir = dir $pwd | ?{$_.PSISContainer} 
$start = $pwd 

foreach ($d in $dir) { 
    cd $d 
    if(Test-Path $fn) { 
     Remove-Item $fn 
    } 
    & git status | Out-File $fn 
    $ss = Select-String -Path $fn -SimpleMatch "Changes not staged for commit" 
    if($ss -ne $null) { 
     $msg = [string]::Format("{0} has modified files", $pwd) 
     Write-Host $msg 
    } 
    $ss = Select-String -Path $fn -SimpleMatch "Untracked files" 
    if($ss -ne $null) { 
     $msg = [string]::Format("{0} has untracked files", $pwd) 
     Write-Host $msg 
    } 
    $ss = Select-String -Path $fn -SimpleMatch "Changes to be committed" 
    if($ss -ne $null) { 
     $msg = [string]::Format("{0} has staged files", $pwd) 
     Write-Host $msg 
    } 
    cd $start 
} 

这里有一个批处理文件,我写信给下JPSoft的tcc.exe命令shell中运行。它可能可以适应cmd.exe或PowerShell。

@echo off 
: Because this needs %_cwd, it must be used with TCC.exe 
@if "%_cmdproc"=="TCC" (goto OK) 

:testTCCLE 
@if NOT "%_cmdproc"=="TCCLE" (goto wrongShell) 

:OK 

global /i /q /s4 (if exist .git\ echo === %_cwd === && git status) 

goto xit 

:wrongShell 
echo TCC/TCCLE required. 

:xit 

这显示了每个git目录的状态;我一直在研究一个版本,只显示没有提交更改的dirs,但尚未完成。另一个改进是显示任何追踪回溯前面或后面的目标。 HTH。

相关问题