Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Find all uncommitted locals repos in a directory tree

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 uncommitted 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 
like image 918
ulver Avatar asked Jun 07 '09 02:06

ulver


1 Answers

Adapted from this gist on how to print git status of all repositories under the current folder:

find . -type d -name '.git' | while read dir ; do sh -c "cd $dir/../ && echo -e \"\nGIT STATUS IN ${dir//\.git/}\" && git status -s" ; done 

The find command is your friend, along with some shell magic.

like image 65
Tasos Koutoumanos Avatar answered Sep 23 '22 06:09

Tasos Koutoumanos