如何判断git repo是否是镜像?

时间:2016-06-07 14:22:04

标签: git

我试图让我的头围绕git镜像。给定工作副本,如何确定它是镜像(还是镜像)另一个存储库?

干杯。

3 个答案:

答案 0 :(得分:4)

尝试:

git config --list | grep remote

remote.origin.url=<git remote url>
remote.origin.fetch=+refs/*:refs/*
remote.origin.mirror=true

我不明白上面列出的细微之处,但这对我有用。

答案 1 :(得分:3)

实际上有两种镜像,如the git remote documentation中所述:

  

使用--mirror=fetch创建提取镜像时,refs会    不存储在 refs / remotes / 命名空间中,而是存储在所有内容中    在遥控器上的 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-repositoryremote.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应为abstract class BaseModel { val dateCreated: String val dateUpdated: String } trait BaseModelCompanion[A <: BaseModel] { implicit val reads: Reads[A] implicit val writes: Writes[A] }

答案 2 :(得分:-1)

Git使用点对点架构。作为镜像的git存储库将出现并且就像它的源一样。为了区分它们,您可以查看“.git / config”文件,因为未按下配置文件,但它不会明确指示它是镜像。