Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

bash - Git Status Across Multiple Repositories on a Mac

I have been searching for a solution to this for a while and have not found quite what I need.

I have several Git Repositories in a folder on my Mac (OSX 10.6) and would like a script or tool that will loop through all the repositories and let me know if any of them needs commiting.

This is my structure

Sites
  /project1
  /project2
  /project3

I want the tool to do a git status in Sites/project1, Sites/project2, Sites/project3 and let me know if any of them have changes or new files that need to be staged or committed.

The closest script I found that might be hackable is here, but even that script wouldn't run, and I get an error:

"syntax error near unexpected token `do"

which might have been written for *nix.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that the question has been answered fine, but I wanted to throw in my two cents after working on the same thing.

I went closer to jcordasc's answer by using a simple bash script. I just did one thing a little different. Looking at the help docs for git you can set the git directory and working directory. This eliminates the need to 'cd' to the directories. Not that it really makes that much difference...

#!/bin/bash

for gitdir in `find ./ -name .git`; 
    do 
        workdir=${gitdir%/*}; 
        echo; 
        echo $workdir; 
        git --git-dir=$gitdir --work-tree=$workdir status; 
    done

Obviously his is more advanced/cleaner for how it shows the status'...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...