How to recursively verify which git files were modified

When you have a project consisting of several git repositories it is difficult to walk manually one by one to discover what have changed.

Today I was trying to know which files I modified on Android project (many git repositories) and I got it done using this command line:

$ find . -name .git -print0 | sed s/\.git//g | xargs -0 -r -I file git --git-dir=file.git --work-tree=file status

Let me to explain it: first I search for all “.git” directory (the repository) and use -print0 to separate each file (in fact it is a git directory) with \null. Then I used “sed” to remove the “.git” directory name from original path name (this is a trick because “–git-dir” needs the complete path name but “–work-tree” needs not, see more ahead) and I passed this base directory (where the “.git” is locate) to xargs. Finally I used the “-I” to save this received path on “file” variable (because I need to use it twice) and added “.git” on it when using “–git-dir” parameter and just “file” for “–work-tree”.

I got all information I needed to create it here:
http://stackoverflow.com/questions/1386291/git-git-dir-not-working-as-expected
http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/

I hope it will be useful to you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s