Mac上多个存储库的Git状态
我已经寻找了一段时间的解决方案,但还没有找到我所需要的 我在Mac(OSX 10.6)上的一个文件夹中有几个Git存储库,我希望有一个脚本或工具可以循环遍历所有存储库,并告诉我是否有任何存储库需要提交 这是我的结构Mac上多个存储库的Git状态,git,bash,macos,shell,Git,Bash,Macos,Shell,我已经寻找了一段时间的解决方案,但还没有找到我所需要的 我在Mac(OSX 10.6)上的一个文件夹中有几个Git存储库,我希望有一个脚本或工具可以循环遍历所有存储库,并告诉我是否有任何存储库需要提交 这是我的结构 Sites /project1 /project2 /project3 我希望该工具在Sites/project1、Sites/project2、Sites/project3中执行git状态,并让我知道其中是否有任何更改或新文件需要暂存或提交 我发现的最接近的脚本可能是
Sites
/project1
/project2
/project3
我希望该工具在Sites/project1、Sites/project2、Sites/project3中执行git状态
,并让我知道其中是否有任何更改或新文件需要暂存或提交
我发现的最接近的脚本可能是可黑客攻击的,但即使该脚本也无法运行,我得到一个错误:
“意外标记'do'附近出现语法错误”
这可能是为*nix编写的。如果您只想了解本地repo中文件的状态,可以这样做:应该这样做。您需要修改
for
循环中的模式,以拾取您想要的任何目录。有一个基于Python的程序,听起来它会完全满足您的需要。目前还没有git支持(只有hg和Subversion),但是你可以帮助作者在他的应用程序中实现git支持,或者将他的想法作为如何实现你的东西的想法(他在我链接的项目页面上记录了他的查找方法)。这个问题似乎已经得到了很好的回答,但在做了同样的事情之后,我想投入我的两分钱
通过使用一个简单的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
显然,his在如何显示状态方面更高级/更清晰,“…这是一个老问题,但我去更新了jcordasc的答案,使其与git 1.7.7.5兼容,我想我也可以在这里提供:
这个版本将任何一个或多个路径作为参数,并为它在参数表示的文件树中找到的任何git存储库提供jcordasc的输出。它还支持检测未推送和未合并的提交。我花了一点时间从@Andrew Roberts处获取代码,以处理一系列文件夹。。如果你在这方面也有问题,请检查一下我的叉子
感谢伟大的脚本@Andrew Roberts和@jcordasc。。这正是我所需要的。同样的问题今天也出现在我的脑海中,除了这一页之外,我发现非常有用,并且有非常好的提示,我也遇到了这个问题。它引入了一个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 mike@mikepearce.net 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)
整件事都在上面。这是一种在一行程序中完成这些事情的简单方法。我错过了最后一步,一旦我发现它,我将添加它(除非其他人知道) 对于
git状态
,您可以执行以下操作:
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投诉,请编辑此答案。使用jsut单个shell别名检查多个回购状态。不需要安装。所有学分归: 对于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)" \;'
很晚才去参加聚会,但我写了一个工具来帮我做到这一点。这是一个简单的shell脚本,可以找到 看起来是这样的:
还有一个ruby gem作为git子命令:
@oxtay的答案是最漂亮的,因此我对其进行了修改,使其更漂亮: 我还修复了一些错误,使其即使在一些混乱的回购协议中也能正常工作,这些回购协议导致@Ferry Boender's抛出错误: @Nathan的ruby one似乎有一个bug,在回购协议正常时给出了一个[错误]: 注意,对于您的常用点击扩展和freeCodeCamp,它是如何显示[ERROR]的。我的和费里会搞定的 如果作为
watch
的子进程运行,我的也会保留它的颜色,这使得清理您的回购协议和实时查看每个回购协议都被勾选变得很方便
OSX是Unix操作系统你直接复制剧本了吗?我并不想成为“那个家伙”,但它对我很有效(即,我在运行它时没有遇到语法错误)。是的,我知道这一点,但我认为我的bash版本缺少一些特殊的Unix功能。我刚刚试着复制了“原始”代码,现在它可以工作了——所以它可能与我以前从网页复制它有关。感谢您确认它可以正常工作。我很快就会尝试,当我第一次尝试使用“raw”模式运行它时,我遇到了相同的语法错误,这可能与换行符有关。一旦我试一试,我会让你知道的。谢谢Ryan!我最终创建了一个支持Git的版本,并请求对bitbucket进行拉取,并在github上创建了我的存储库—os x用户,安装do:sudo easy\u install pip->sudo pip install uncommitted->uncommitted~主版本现在支持Git。老实说,我更愿意将此作为对jcordasc答案的评论发布,但如果我能看到如何实现这一点,那就该死了……你可以使用
Git-C$gitdir
而不是--gitdir
,并且--工作树
选项。因此do块的最后一行变成git-C$gitdir status代码>。当我尝试运行它时,缩进中的制表符和空格使用不一致。
# install the gem
gem install git-status-all
# use the status-all subcommand to scan the directory
git status-all
./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
$ 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