git:在目录树中查找所有未被取消的本地人回购 [英] git: Find all uncommited locals repos in a directory tree
问题描述
我的文件系统上有一堆(10-15)本地git存储库,但都在文件夹/ data /
中,我想查找所有/任何有未得到改变的文件夹。我怎样才能做到这一点?有点像一个递归的全局 git status
variant。
所有的答案都错了,我想。任何git命令只能在git控制下的文件夹中使用。我需要一些东西来搜索这样的文件夹。
所以我写了这样的脚本:
$ b $ >
#!/ usr / bin / env ruby
require'find'
require'fileutils'
#supply目录作为参数搜索
$ b除非@pat
Dir.chdir(@pat)
Find.find(@pat)do | $ b @pat = ARGV [0]
(putsdirectory argument required路径|
如果FileTest.directory?(path)
Dir.chdir(路径)
resp =`git status 2>&1`
除非resp =〜/ fatal |不需要提交\\ \\(工作目录clean \)/ i
puts#{'#'* 10} \\\
#{Dir.pwd}#{'#'* 10} \ n#{resp}
Find.prune
end
Dir.chdir(@pat)
end
end
解决方案find 与一些shell魔术。
find。 -type d -name'.git'|同时阅读dir; do sh -ccd $ dir /../&& echo -e \\\\
GIT STATUS IN $ {dir // \.git /} \&&&git status -s ;完成
from:https://gist.github.com/tafkey/664266c00387c98631b3
I have a bunch(10-15) of local git repositories somewhere on my filesystem, but all in the folder /data/
I want to find all/any folder that has uncommited changes. How can I do that? Kind of like a recursive global
git status
variant.All the answers got it wrong i think. Any git command only works within the folder that's under git control. I need something to search for such folders.
So instead I wrote this script that does this:
#!/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
解决方案The
find
command is your friend, along with some shell magic.find . -type d -name '.git' | while read dir ; do sh -c "cd $dir/../ && echo -e \"\nGIT STATUS IN ${dir//\.git/}\" && git status -s" ; done
这篇关于git:在目录树中查找所有未被取消的本地人回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文