2010-05-04 79 views
17

我一直在尋找一個解決方案,並且一直沒找到我需要的東西。Mac上的多個存儲庫上的Git狀態

我在我的Mac(OSX 10.6)上的文件夾中有幾個Git存儲庫,並且想要一個腳本或工具來循環訪問所有的存儲庫,並讓我知道它們是否需要commit ing。

這是我的結構

Sites 
    /project1 
    /project2 
    /project3 

我想要的工具,做網站一git status/PROJECT1,網站/項目2,網站/項目3,讓我知道其中是否有變化或新文件需要上演或承諾。

我發現可能被破解is here,但即使這樣腳本將不會運行最接近的腳本,我得到一個錯誤:這可能會在* nix已被寫入

"syntax error near unexpected token `do"

+3

OS X *是* Unix。 ;)你是否直接複製腳本?我不是想成爲「那個人」,但它對我有用(即,我在運行時沒有遇到語法錯誤)。 – mipadi 2010-05-04 12:52:05

+0

是的,我知道,但我覺得我的bash版本缺少一些特殊的Unix功能。我只是試圖複製「原始」代碼,現在它可以工作 - 所以它可能與我之前從網頁上覆制它有關。感謝您確認它的工作原理。 – eapen 2010-05-04 15:02:51

回答

12

有一個基於Python的程序,uncommitted,聽起來像它會做你想要的。目前還沒有對git的支持(只是hg和Subversion),但你可以幫助作者在他的應用中實現git支持,或者將他的想法作爲如何實現你的東西(他在項目頁面上記錄他的發現方法我鏈接到)。

+0

謝謝,這看起來很有前途。 – eapen 2010-05-06 15:40:10

+7

謝謝瑞恩!我最終創建了一個具有Git支持的版本,並請求在bitbucket上進行拉取,並在github上創建了我的存儲庫 - http://github.com/eapen/uncommitted – eapen 2010-05-08 08:42:47

+0

os x用戶,要安裝do:sudo easy_install pip - > sudo pip install uncommitted - > 未提交〜 – 2013-11-28 04:23:36

4

如果你只是想狀態的文件在本地回購,像這樣的:http://gist.github.com/389478應該做的伎倆。您需要修改for循環中的模式以獲取所需的任何目錄。

+0

我會盡快嘗試,當我第一次嘗試使用「原始」模式運行時,我得到了相同的語法錯誤,這可能與換行符有關。一旦我給了這個鏡頭,我會讓你知道的。 – eapen 2010-05-06 15:41:19

+0

這對我來說效果非常好,謝謝發帖 – subelsky 2012-05-23 15:49:40

23

似乎這個問題已經被很好的回答了,但是我想在完成同樣的事情之後投入我的兩分錢。

我用一個簡單的bash腳本接近jcordasc的答案。我只是做了一件有點不同的事情。查看git的幫助文檔,您可以設置git目錄和工作目錄。這消除了「cd」到目錄的需要。不,那真叫相差太大......

#!/bin/bash 

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

顯然他是更先進/清潔它是如何顯示的狀態......

+0

老實說,我會非常寧願張貼這個作爲評論jcordasc的答案,但該死的,如果我能看到如何做到這一點... ... – Woody2143 2010-06-08 16:45:38

+0

好又簡單! – eapen 2010-06-09 13:43:35

+0

您可以使用'git -C $ gitdir'而不是'--gitdir'和'--work-tree'選項。所以do塊的最後一行變成'git -C $ gitdir status;'。 – 2017-05-10 07:49:17

5

這是一個老問題,但我去了,更新jcordasc的回答所以它的工作原理與GIT 1.7.7.5,我想我不妨在這裏有助於它:

https://gist.github.com/3018100

這個版本採用的任何路徑或作爲參數的路徑,並給出jcordasc的輸出任何的Git倉庫它在文件樹中的任何地方找到由參數代表。它還支持檢測未提交和未提交的提交。

2

我花了一些時間來得到@Andrew羅伯茨的代碼文件夾的數組工作。如果您遇到麻煩太多,在https://gist.github.com/3666392

感謝檢查我的叉子偉大的腳本@Andrew Roberts和@jcordasc ..正是我需要的。

+0

+1。非常有用的腳本! – 2013-07-30 19:48:37

2

同樣的問題也出現在我今天和本頁以外,我發現非常有用和非常好的提示,我也遇到了following blog post。它引入了一個python腳本,它的確如此:

Usage: show_status [options] 

Show Status is awesome. If you tell it a directory to look in, it'll scan 
through all the sub dirs looking for a .git directory. When it finds one it'll 
look to see if there are any changes and let you know. It can also push and 
pull to/from a remote location (like github.com) (but only if there are no 
changes.) Contact [email protected] for any support. 

Options: 
    -h, --help   show this help message and exit 
    -d DIRNAME, --dir=DIRNAME 
         The directory to parse sub dirs from 
    -v, --verbose   Show the full detail of git status 
    -r REMOTE, --remote=REMOTE 
         Push to the master (remotename:branchname) 
    -p PULL, --pull=PULL Pull from the master (remotename:branchname) 

整個事情位於this git repo

+0

當我嘗試運行它時,我得到'縮進中的標籤和空格不一致的使用。 – Zenadix 2015-11-09 19:54:33

0

這是一個簡單的方法,在一個班輪做這種事情。我找不到最後一步,一旦找到它,我會添加(除非其他人知道它)。

對於git status,你可以這樣做:

find ./Sites -name .git | awk '{ print "git --git-dir=" $1 " --work-tree " substr($1,1,length($1) - 4) " status" }' 

然後複製輸出,並執行它。

對於一個完整的差異,你可以運行:

find ./Sites -name .git | awk '{ print "git --git-dir=" $1 " --work-tree " substr($1,1,length($1) - 4) " --no-pager diff" }' 

複製粘貼的東西,你必須做讓我很煩。還應當xargs用在那裏,但不知何故,git的抱怨:

find ./Sites -name .git | awk '{ print "--git-dir=" $1 " --work-tree " substr($1,1,length($1) - 4) " --no-pager diff" }' | xargs git 

如果有人知道如何解決git的投訴在這最後的命令,請編輯這個答案。

4

使用jsut單個shell別名進行多次回購狀態檢查。不需要安裝。所有學分:https://coderwall.com/p/grmruq/git-status-on-all-repos-in-folder

對於bash:

alias gitstat='find . -maxdepth 1 -mindepth 1 -type d -exec sh -c "(echo {} && cd {} && git status -s && echo)" \;' 
alias gitstatfull='find . -maxdepth 1 -mindepth 1 -type d -exec sh -c "(echo {} && cd {} && git status && echo)" \;' 

或Cshell

alias gitstat   'find . -maxdepth 1 -mindepth 1 -type d -exec sh -c "(echo {} && cd {} && git status -s && echo)" \;' 
alias gitstatfull  'find . -maxdepth 1 -mindepth 1 -type d -exec sh -c "(echo {} && cd {} && git status && echo)" \;' 
1

非常遲到了,但我寫了一個工具來幫我這個忙。這是一個簡單的shell腳本,可以發現on Github.

它看起來像這樣:

Projects/fboender/multi-git-status: Uncommitted changes; Projects/fboender/jerrybuild.tst: Needs push (doc, master); Projects/fboender/multi-git-status.bak: Needs push (master); Projects/fboender/tempita: ok; Projects/fboender/dirigent: Uncommitted changes Untracked files; Projects/flusso/boxes: ok; Projects/flusso/docker: ok; Projects/flusso/deployments: ok; Projects/flusso/backup: ok;

0

還爲這一個紅寶石的寶石,可以作爲一個git子命令:https://github.com/reednj/git-status-all

# install the gem  
gem install git-status-all 

# use the status-all subcommand to scan the directory 
git status-all 

git status all

0

@oxtay的答案是最漂亮的,所以我modifi ED它,使其更漂亮:https://github.com/Flurrywinde/Git-Status

我還修正了一些錯誤,並使其與一些搞砸回購導致@Ferry Boender的拋出錯誤甚至工作:

./git-ftp: ok 
./kphotoalbum: ls: cannot access './kphotoalbum/.git/refs/heads': No such file or directory 
fatal: Not a git repository: './kphotoalbum/.git' 
fatal: Not a git repository: './kphotoalbum/.git' 
fatal: Not a git repository: './kphotoalbum/.git' 
Uncommitted changes 
./SemanticForms: Uncommitted changes 
./git-big-picture: Uncommitted changes Untracked files 
./10-minute-vim-exercises: ok 
./moviemasher: Uncommitted changes 
./tumbdlwtf: Uncommitted changes 
./rotatezoomHTML5video: Uncommitted changes 
./tumbdl: Needs push (master) 
.: ls: cannot access './python/refs/heads': No such file or directory 
fatal: Not a git repository: './python' 
fatal: Not a git repository: './python' 
fatal: Not a git repository: './python' 
Uncommitted changes 
.: ls: cannot access 'mediawiki/refs/heads': No such file or directory 
fatal: Not a git repository: 'mediawiki' 
fatal: Not a git repository: 'mediawiki' 
fatal: Not a git repository: 'mediawiki' 
Uncommitted changes 
parser: ls: cannot access 'parser/.git/refs/heads': No such file or directory 
fatal: Not a git repository: 'parser/.git' 
fatal: Not a git repository: 'parser/.git' 
fatal: Not a git repository: 'parser/.git' 
Uncommitted changes 
./gundo.orig: Uncommitted changes 
./wikiteam: Uncommitted changes Untracked files 

@ Nathan的紅寶石一個似乎有一個bug,給人一種[錯誤]當回購是好的:

$ git status-all 
yourls-popular-clicks-extended              [ERROR] 
undefined local variable or method `s' for "yourls-popular-clicks-extended":String 
miniProxy                   [master] 
dmenu-4.6-kanon   M15U37             [master] 
freeCodeCamp                  [ERROR] 
undefined method `up_to_date?' for nil:NilClass 

$ mgitstatus      
./yourls-popular-clicks-extended: ok 
./miniProxy: ok 
./dmenu-4.6-kanon: Uncommitted changes Untracked files 
./freeCodeCamp: Untracked files 

注意它是如何說[錯誤]關於YOURLS流行,點擊擴展和freeCodeCamp。礦和渡輪的正確。

如果作爲watch的子流程運行,礦山也會保留它的顏色,這樣可以方便地清理您的倉庫並查看每個倉庫的實時情況。

Screenshot of mine in a tmux session where I'm cleaning up the repos