【发布时间】:2010-10-31 23:00:23
【问题描述】:
我的文件系统中某处有一堆 (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
【问题讨论】: