有没有办法在终端中列出 git 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5101485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:06:15  来源:igfitidea点击:

Is there any way to list up git repositories in terminal?

gitterminal

提问by studiomohawk

I have several git repositories on my system and I want to list them all in terminal.

我的系统上有几个 git 存储库,我想在终端中列出它们。

What I'm looking for is something like this:

我正在寻找的是这样的:

/path/to/my/git/repo/1/ REPONAME1
/path/to/my/git/repo/2/ REPONAME2
/path/to/my/git/repo/3/ REPONAME3

/path/to/my/git/repo/1/ REPONAME1
/path/to/my/git/repo/2/ REPONAME2
/path/to/my/git/repo/3/ REPONAME3

If you can come up with how to show branch name and repo's status eg. [master] c:0 u:1 d:0, that would be great.

如果你能想出如何显示分支名称和回购的状态,例如。[master] c:0 u:1 d:0,那太好了。

采纳答案by Adrian Pillinger

To list all the git repositories you have on your system you can run the following command in a bash shell terminal (at the command line) and find them.

要列出您系统上的所有 git 存储库,您可以在 bash shell 终端(在命令行)中运行以下命令并找到它们。

find / -name .git -type d -exec dirname {} \;

回答by William Jamieson

I found this more accurate than the find command and much faster. I'm sure it can be improved but it's a good start. Obviously your file database will need to be up-to-date before running this command. On linux systems you can do this by running 'updatedb'.

我发现这比 find 命令更准确,而且速度更快。我相信它可以改进,但这是一个好的开始。显然,在运行此命令之前,您的文件数据库需要是最新的。在 linux 系统上,您可以通过运行“ updatedb”来做到这一点。

locate -br '\.git$' | rev | cut -c 6- | rev

回答by Dee Newcum

lsgitis a script that does this. It's essentially a wrapper around locate -br '^HEAD$'.

lsgit是一个执行此操作的脚本。它本质上是一个围绕locate -br '^HEAD$'.

If there are multiple clones of the same repo on the local machine, it will indicate that those repos are related.

如果本地机器上有同一个 repo 的多个克隆,则表明这些 repo 是相关的。

回答by nrbray

A wrapper around:
locate -br '^HEAD$'as done by Dee Newcum https://github.com/DeeNewcum/dotfiles/blob/master/bin/lsgitor else find . -name 'HEAD'as modified in https://gist.github.com/nrbray/a0ae8ec59d1fd1ae03e2947368096d2e

一个包装器:
locate -br '^HEAD$'由 Dee Newcum https://github.com/DeeNewcum/dotfiles/blob/master/bin/lsgitfind . -name 'HEAD'https://gist.github.com/nrbray/a0ae8ec59d1fd1ae03e2947368096d2e 中修改

gives an alternative to searching for gits by the folder or filename alone.

提供了单独按文件夹或文件名搜索 gits 的替代方法。

[Not enough reputation to comment on Dee's answer, but I used his solution and it worked for me]

[没有足够的声誉来评论 Dee 的回答,但我使用了他的解决方案并且对我有用]