如何查看我机器上的所有 git 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2020812/
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
How can I view all the git repositories on my machine?
提问by n1kh1lp
Is there a way in which I can see all the git repositories that exist on my machine? Any command for that?
有没有办法可以看到我机器上存在的所有 git 存储库?有什么命令吗?
采纳答案by Arkaitz Jimenez
If you are in Linux find / -name ".git"
, otherwise there is no way, they are standard directories, just use your OS file/folder find program to find .git
named folders.
如果您在 Linux 中find / -name ".git"
,否则没有办法,它们是标准目录,只需使用您的操作系统文件/文件夹查找程序来查找.git
命名文件夹。
回答by bopapa_1979
ORIGINAL ANSWER: This works pretty well from Windows Powershell:
原始答案:这在 Windows Powershell 中运行良好:
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Include ".git" -Recurse
EDIT #1: -Filter is twice as fastas -Include. Here is that solution:
编辑#1:-Filter 是-Include 的两倍。这是解决方案:
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse
EDIT #2: Keith E. Truesdellmentioned sending the output to a file. See his comment for that solution. I prefer console output. But his comment got me thinking that I prefer just the full path, not the whole mess that is returned by default. If you want that just the full path, use the following:
编辑 #2: Keith E. Truesdell提到将输出发送到文件。请参阅他对该解决方案的评论。我更喜欢控制台输出。但是他的评论让我觉得我更喜欢完整路径,而不是默认返回的整个混乱。如果您只想要完整路径,请使用以下命令:
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse | % { Write-Host $_.FullName }
FINAL NOTE: The above solutions only return Git repositories under the current directory. If you want ALL repositories on a drive, you should run the command once from the root of each drive.
最后说明:上述解决方案仅返回当前目录下的 Git 存储库。如果您希望驱动器上的所有存储库,您应该从每个驱动器的根目录运行该命令一次。
回答by gahooa
On *nix, this will also find any --bare
repositories.
在 *nix 上,这也会找到任何--bare
存储库。
find / -name "*.git" -type d
回答by jthill
Git repositories all have HEAD
, refs
and objects
entries.
Git 存储库都有HEAD
,refs
和objects
条目。
on GNU/anything,
在 GNU/任何东西上,
find -name HEAD -execdir test -e refs -a -e objects \; -printf %h\n
Just checking for .git
will miss many bare repos and submodules.
仅仅检查.git
就会错过许多裸仓库和子模块。
To go full-paranoid on the checking you can ask git to do all its own checks before printing,
要在检查中完全偏执,您可以要求 git 在打印之前进行所有自己的检查,
find -name HEAD -execdir test -e refs -a -e objects \; \
-execdir sh -ec 'GIT_DIR=$PWD git rev-parse --absolute-git-dir 2>&-' \;
(edit: I thought the .git/config
file was necessary, turns out it's not, so the absolute minimum git init newrepo
is
(编辑:我认为该.git/config
文件是必要的,事实证明它不是,所以绝对最小值git init newrepo
是
mkdir -p newrepo/.git/{objects,refs}
echo ref: refs/heads/master >newrepo/.git/HEAD
)
)
回答by Ernesto
On Linux, a faster way would be:
在 Linux 上,更快的方法是:
locate -r "\.git$"
locate -r "\.git$"
assuming you keep locate's database updated with sudo updatedb
假设您保持 locate 的数据库更新 sudo updatedb
回答by Walter Tross
On Linux and OS X the following command is possibly the fastest (ignoring repositories without .git
) when the root directory of find
is /
:
在Linux和OS X下面的命令可能是最快的(忽略不存储库.git
)时的根目录find
是/
:
find / -name .git -exec dirname {} \; -prune
But for roots that have mostly repositories underneath, the following is probably the fastest (you may want to replace /
with .
or another root):
但是对于下面主要有存储库的根目录,以下可能是最快的(您可能想要替换/
为.
或另一个根目录):
find / -type d -exec test -d {}/.git \; -prune -print
Quick explanation of the primariesof find
used (since no operatorsare present here, -and
is implicit, i.e., for each visited node primariesare evaluated left to right until one of them evaluates to false
):
对used的原色的快速解释find
(因为这里没有运算符,所以-and
是隐式的,即,对于每个访问过的节点,从左到右计算原色,直到其中一个计算为false
):
-name
istrue
if the name matches (often, but not here, with wildcards)-exec
executes a command terminated by;
(which is escaped by\
to avoid interpretation by the shell), and istrue
if the return status is0
(i.e., OK). The current node is available as{}
(which needs no escaping)-prune
is alwaystrue
, and causes all child nodes to be skipped-type d
istrue
for directories-print
is needed here because if-exec
is present it is not implicitly appended
-name
是true
如果名称匹配(通常,但不在这里,使用通配符)-exec
执行由终止的命令;
(它被转义\
以避免被shell解释),并且true
如果返回状态是0
(即OK)。当前节点可用{}
(不需要转义)-prune
is alwaystrue
,并导致跳过所有子节点-type d
是true
对目录-print
此处需要,因为如果-exec
存在,则不会隐式附加
回答by Michel Gokan
On Linux, try this command with root permission:
在 Linux 上,使用 root 权限尝试此命令:
find / | grep \.git$
this just searchs every files that end with .git ... you can do it with searching tools in Windows, Linux etc...
这只是搜索以 .git 结尾的每个文件......你可以使用 Windows、Linux 等中的搜索工具来完成......
回答by Julien Brdy
A simple PowerShell version:
一个简单的 PowerShell 版本:
Get-ChildItem . -Recurse -Hidden .git
回答by Display name
Small variation from Eric Burcham's answer. That answer adds \.git to end, this one doesn't.
与 Eric Burcham 的回答略有不同。该答案将 \.git 添加到结尾,而这个答案没有。
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse | % { Write-Host $_.Parent.FullName }
I use this command at the beginning of the day. It simply adds a few git commands to the above. For some reason, our git repository works best if one runs a fetch then pull, don't know why. And we have a lot of submodules for some reason. Anyway, put what you need in between the {}'s.
我在一天开始时使用这个命令。它只是在上面添加了一些 git 命令。出于某种原因,我们的 git 存储库在运行 fetch 然后拉取时效果最佳,不知道为什么。出于某种原因,我们有很多子模块。无论如何,将您需要的放在 {} 之间。
push-location; Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse | % { cd $_.parent.fullname; write-host '*************'; $(get-location).path; git fetch; git pull; git checkout .; git clean -f; git submodule update; git status; write-host '*************'; write-host ' '; }; pop-location
回答by InLaw
For Linux:
对于 Linux:
dir="/home/${USER}"
dir_not="${dir}/miniconda3"
find /home/aeug -type d -iname ".git" -o -path "${dir_not}" -prune | xargs -0 echo