查找包含有效git裸存储库的文件夹 [英] Looking for folders containing valid git bare repositories

查看:90
本文介绍了查找包含有效git裸存储库的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大容量存储中,如何检测仅包含裸git存储库的所有文件夹?

In big storages, how to detect all folders containing only bare git repositories?

我不是要查找git裸存储库的常规内容或某些内容,而是真正的有效存储库.

I don't mean just looking for the usual content or some content of git bare repositories, but real valid repositories.

当前方法:

此处的答案只是找到具有基本内容的文件夹,这些内容可能看起来像git裸存储库,因此我们可以对其进行改进尝试在与该基本结构匹配的每个文件夹上执行git status,但是我不确定这是否是确保这是一个裸存储库的最佳方法,更不用说git status在需要该裸存储库的情况下返回错误fatal: this operation must be run in a work tree我们假设它意味着一个光秃秃的仓库.因此,我们必须期望每次检查都会收到该输出,并且仅因此假设它是有效的git裸存储库.

The answer here just find folders having basic content that may look like a git bare repository, so we could improve it trying to execute git status on every folder matching this basic structure, but I'm not sure it would be the best approach to ensure this is a bare repository, not to say that git status returns the error fatal: this operation must be run in a work tree on bare repositories requiring us to assume it means a bare repository. So we would have to expect to receive that output for each checking and only thus assume it's a valid git bare repository.

有没有更好的方法来找到它们?

Is there any better way to find them?

推荐答案

您应该按照Git检测到它们的方式来检测它们,这在您引用的答案中有概述.要发挥作用,您需要满足以下条件:

You should detect them the way Git detects them, which is outlined in the answer you quoted. To wit, you need the following:

  • objects/目录;
  • 一个refs/目录;和
  • HEAD符号链接或格式正确的HEAD文件.
  • an objects/ directory;
  • a refs/ directory; and
  • either a HEAD symlink or a HEAD file that is properly formatted.

确切的规范记录在setup.c的源代码中.

The exact specification is documented in the source code in setup.c.

如果您怀疑是Git存储库,则可以将其更改并运行git rev-parse --git-dir,如果您在Git存储库中,则将成功退出,否则,则退出失败.您还可以使用git rev-parse --is-bare-repository并查找truefalse来确定您的存储库是否为空.

If you have what you suspect is a Git repository, you can change into it and run git rev-parse --git-dir, which will exit successfully if you're in a Git repository, and exit unsuccessfully if you're not. You can also use git rev-parse --is-bare-repository and look for either true or false to determine whether your repository is bare.

如果您不想更改为存储库,则可以使用git -C <DIR> rev-parse --git-dir和类似的命令对提到的目录进行操作.

If you don't want to change into the repository, you can use git -C <DIR> rev-parse --git-dir and similar to operate on the mentioned directory instead.

这篇关于查找包含有效git裸存储库的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆