小智 6
尝试:
git config --list | grep remote
remote.origin.url=<git remote url>
remote.origin.fetch=+refs/*:refs/*
remote.origin.mirror=true
Run Code Online (Sandbox Code Playgroud)
我不明白上面列出的微妙之处,但这对我有用。
正如文档中所述,实际上有两种镜子:git remote
当使用 创建 fetch 镜像时
--mirror=fetch,refs 不会存储在refs/remotes/命名空间中,而是远程上refs/中的所有内容都将直接镜像到本地存储库中的refs/中。此选项仅在裸存储库中有意义,因为提取会覆盖任何本地提交。当使用 创建推送镜像 时
--mirror=push,thengit 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/*
$
Run Code Online (Sandbox Code Playgroud)
检测推镜更简单:
$ git remote add --mirror=push rpush ssh://upstream.host/path/to/repo.git
$ git config --get --bool remote.rpush.mirror
true
Run Code Online (Sandbox Code Playgroud)
如果特定设置为,但存储库未设置为(您可以使用或 来发现;两者都执行相同的操作),则您将得到一个混乱的存储库(例如我为说明上述内容而制作的存储库:-))。如果有多个部分,并且其中任何一个都有,那么您就有一个奇怪的存储库(理论上,具有多个遥控器的获取镜像可以作为一种联合存储库,但所有遥控器都需要使用不同的引用,例如,只有一个可以拥有分支)。您可以使用or查找所有遥控器并提取与正则表达式匹配的项目。如果编写脚本,这实际上可能是最合适的处理器:remote.remote.fetch+refs/*:refs/*core.baretruegit config --get --bool core.baregit rev-parse --is-bare-repositoryremote.remotefetch=+refs/*:refs/*mastergit config --get-regexpgit config --list^remote\.awk
$ git config --list | awk -F. '$1 == "remote" { if (!r[$2]++) print $2 }'
rfetch
rpush
$
Run Code Online (Sandbox Code Playgroud)
获得远程列表后,您可以以获取或推送镜像的方式探测每个远程的镜像性。如果有一个 fetch 镜像,core.bare应该是true.