ulv*_*ver 20 git scripting file
我的文件系统上有一堆(10-15)本地git存储库,但所有文件夹/ data /
我想找到所有/任何具有未经修改的更改的文件夹.我怎样才能做到这一点?有点像递归的全局git status变体.
我认为所有答案都错了.任何git命令只能在git控件下的文件夹中工作.我需要一些东西来搜索这样的文件夹.
所以我写了这个脚本来做到这一点:
#!/usr/bin/env ruby
require 'find'
require 'fileutils'
#supply directory to search in as argument
@pat = ARGV[0]
(puts "directory argument required"; exit) unless @pat
Dir.chdir(@pat)
Find.find(@pat) do |path|
if FileTest.directory?(path)
Dir.chdir(path)
resp = `git status 2>&1`
unless resp =~ /fatal|nothing to commit \(working directory clean\)/i
puts "#{'#'*10}\n#{Dir.pwd}#{'#'*10}\n#{resp}"
Find.prune
end
Dir.chdir(@pat)
end
end
Run Code Online (Sandbox Code Playgroud)
Tas*_*nos 16
这个find命令是你的朋友,还有一些shell魔法.
find . -type d -name '.git' | while read dir ; do sh -c "cd $dir/../ && echo -e \"\nGIT STATUS IN ${dir//\.git/}\" && git status -s" ; done
Run Code Online (Sandbox Code Playgroud)
沿着这些方向的东西?
$ for i in /data/*/; do (cd $i && (echo $i; git status)); done $ for i in /data/*/; do (cd $i \ > && (git status | grep -qx 'nothing to commit (working directory clean)' \ > || (echo $i && git status))); done
我不认为 git 有这个内置,因此我(也)创建了一个脚本来做到这一点:https : //github.com/mnagel/clustergit
此处发布的片段的问题在于它们会随着git status更改的输出格式而中断。我的脚本有同样的问题(因为它基本上以相同的方式工作),但至少你总是得到最新版本。

确实不需要花哨的 bash 愚蠢的行为,只需使用 find 即可。
find . -type d -name .git -print -execdir git status \;
Run Code Online (Sandbox Code Playgroud)
find . -type d -name .git递归查找所有.git存储库-print.git打印目录的路径-execdir git status \;在该目录中运行git status(包含 git 目录的目录)