I've got multiple git repos under a directory, and I was wondering whether there was some functionality in git to iterate each directory, check whether there are any uncommitted changes and report those to me?
I could run this every morning to ensure everything is up to date.
It's just that on any one day, I'll be working with multiple repos and I'll forget to commit my changes, which can cause conflicts when I realise mu开发者_如何学Goch later on to commit them.
Chris
Andy is right (in the comments): if the parent directory is itself the root directory of a parent repo, with all the subdirectories as submdules, then git status can detect any changes in one of them.
You can also use (with submodules) git diff
git submodule foreach --recursive git diff --name-status
Without submodules, see a scripting solution at "git: Find all uncommited locals repos in a directory tree".
I wrote a command-line tool gita for this purpose. It can display the status of all repos, including the edit status, the relation to remote branch, etc. It also batch executes commands from any working directory.
You can also group the repos. For your project structure, you can run
gita add -r <root>
which will automatically add the subordinate repos into a group.
Then gita ll root
will display the relevant information. gita <command> root
will batch run the command on repos in the root group. You can surely run command on specified repos from any working directory too.
There are other functionalities such as setting context, defining custom commands, etc. Installation is pip3 install -U gita
. You can find more information on github.
The gita ll
command shows 3 possible symbols next to the branch name, which indicates
+
: staged changes*
: unstaged changes_
: untracked files/folders
The branch names are colored in 5 ways
color | meaning |
---|---|
white | local has no remote |
green | local is the same as remote |
red | local has diverged from remote |
purple | local is ahead of remote (good for push) |
yellow | local is behind remote (good for merge) |
Maybe https://metacpan.org/module/rgit might help :)
Add this alias to your .gitconfig
file and then you can run git status-all
from a parent directory to get the status of all git repositories recursively.
[alias]
status-all = "!for d in `find . -name \".git\"`; do echo \"\n*** Repository: $d ***\" && git --git-dir=$d --work-tree=$d/.. status; done"
I don't think git has this build in, thus some time ago I created a script to do this: https://github.com/mnagel/clustergit
clustergit
allows you to run git commands on multiple repositories at once. It is especially useful to run git status recursively on one folder. clustergit
supports git status
, git pull
, git push
, and more.
In case someone needs a one liner:
rootdir=$(pwd);for folder in $(ls -p | grep /);do cd "$rootdir/$folder";git status; cd $rootdir; done
精彩评论