如何判断一个git回购是否是一面镜子?
有实际上2种镜,如在the git remote
documentation注意到:
当取镜与
--mirror=fetch
创建,裁判将 不被存储在参/遥控器/名称空间,而是将远程中的所有 refs/直接镜像到refs/中的 本地存储库中。此选项仅在 存储库中才有意义,因为提取会覆盖任何本地提交。当使用
--mirror=push
创建推式镜像时,git push
将始终表现为好像--mirror
已通过。
一个取镜(这是你会得到什么,如果你使用git clone --mirror
)通过它的两个键设置为检测,core.bare
及其fetch
行:
$ git remote add --mirror=fetch rfetch ssh://upstream.host/path/to/repo.git
$ git config --get-all remote.rfetch.fetch
+refs/*:refs/*
$
检测推镜更简单:
$ git remote add --mirror=push rpush ssh://upstream.host/path/to/repo.git
$ git config --get --bool remote.rpush.mirror
true
如果特定remote.remote.fetch
设置为+refs/*:refs/*
但确实库不已将core.bare
设置为true
(您可以使用git config --get --bool core.bare
或git rev-parse --is-bare-repository
发现;两者都做同样的事情),你有一个困惑的存储库(例如我所做的以上说明:-))。如果有多个remote.remote
部分,并且它们中的任何一个都有fetch=+refs/*:refs/*
,那么您有一个最好的存储库(理论上,具有多个遥控器的提取镜像可以用作联合存储库,但所有遥控器都需要使用不同的参考文献,例如,只有一个可能有一个master
分支)。您可以使用git config --get-regexp
或git config --list
找到所有遥控器,并提取与正则表达式^remote\.
匹配的项目。这里awk
实际上也许如果编写脚本的最合适的处理器:在获得遥控器的列表
$ git config --list | awk -F. '$1 == "remote" { if (!r[$2]++) print $2 }'
rfetch
rpush
$
,那么你就可以探测每一个用于其镜面的烦躁或者作为提取或推镜。如果有的话是取镜子,core.bare
应该是true
。
Git使用对等体系结构。作为镜像的git存储库将出现,并且就像它的源代码一样。为了区分它们,你可以查看'.git/config'文件,因为配置文件没有被压入,但是它不会明确指出它是一个镜像。
尝试:
git config --list | grep remote
remote.origin.url=<git remote url>
remote.origin.fetch=+refs/*:refs/*
remote.origin.mirror=true
我不明白上面列出的细微之处,但为我工作。