git clone --mirror和git clone --bare有什么区别? [英] What's the difference between git clone --mirror and git clone --bare

查看:1861
本文介绍了git clone --mirror和git clone --bare有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git克隆帮助页面可以说 - 镜像


设置远程存储库的镜像。这意味着 - 裸露


但没有详细说明如何 - 镜像克隆与 - 裸克隆不同。

解决方案

不同之处在于,当使用 - mirror 时,所有 refs被复制原样。这意味着一切:远程跟踪分支,注释,参考/原件/ *(来自过滤分支的备份)。克隆回购有这一切。它也被设置,以便远程更新将从原点重新获取所有内容(覆盖复制的参考)。这个想法实际上是为了镜像存储库,拥有一个完整的副本,以便您可以在多个地方托管您的中央回购站,或备份它。想想直接复制回购,除了以更优雅的git方式。



新的 documentation 几乎都说明了这一切:


- 镜像



设置源存储库的镜像。这意味着 - 裸露。与 - bare 相比, - mirror 不仅将源的本地分支映射到目标的本地分支,它会映射所有的引用(包括远程分支,注释等),并设置一个refspec配置,使得所有这些引用都被目标库中的 git remote update 覆盖。


我的原始答案还指出了裸露克隆和正常(非裸露)克隆之间的区别 - 设置了非裸露克隆远程跟踪分支,只为 HEAD 创建一个本地分支,而裸分支直接复制分支。



假设来源有几个分支( master(HEAD) next pu maint ),一些标签( v1 v2 v3 ),一些远程分支( devA / master devB / master )和其他一些参考( refs / foo / bar refs / foo / baz ,这可能是笔记,斯塔斯hes,其他开发者的名字空间,谁知道)。




  • git clone origin-url 将获得所有被复制的标签,一个本地分支 master(HEAD)跟踪远程分支 origin / master ,以及远程分支机构 origin / next origin / pu origin / maint 。跟踪分支的设置是这样的,如果你做了像 git fetch origin 之类的东西,它们就会像你期望的那样被抓取。任何远程分支(在克隆的远程)和其他参考都完全忽略。

  • code>:你将得到所有被复制的标签,本地分支 master(HEAD) next pu maint ,没有远程追踪分支。也就是说,所有分支都是按照原样复制的,并且它的设置完全独立,不需要再次获取。任何远程分支(在克隆的远程)和其他引用都被完全忽略。 code>:这些参考文献中的每一个都将按照原样复制。你会得到所有的标签,本地分行 master(HEAD) next pu maint ,远程分支 devA / master devB / master ,其他refs refs / foo / bar refs / foo / baz 。一切都与克隆的遥控器完全相同。远程跟踪设置为,如果您运行 git remote update ,则所有参考将从原点被覆盖,就像您刚刚删除了镜像并对其进行了克隆一样。正如文件最初所说,这是一面镜子。它应该是一个功能完全相同的复制品,可与原始文件互换。

The git clone help page has this to say about --mirror:

Set up a mirror of the remote repository. This implies --bare.

But doesn't go into detail about how the --mirror clone is different from a --bare clone.

解决方案

The difference is that when using --mirror, all refs are copied as-is. This means everything: remote-tracking branches, notes, refs/originals/* (backups from filter-branch). The cloned repo has it all. It's also set up so that a remote update will re-fetch everything from the origin (overwriting the copied refs). The idea is really to mirror the repository, to have a total copy, so that you could for example host your central repo in multiple places, or back it up. Think of just straight-up copying the repo, except in a much more elegant git way.

The new documentation pretty much says all this:

--mirror

Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.

My original answer also noted the differences between a bare clone and a normal (non-bare) clone - the non-bare clone sets up remote tracking branches, only creating a local branch for HEAD, while the bare clone copies the branches directly.

Suppose origin has a few branches (master (HEAD), next, pu, and maint), some tags (v1, v2, v3), some remote branches (devA/master, devB/master), and some other refs (refs/foo/bar, refs/foo/baz, which might be notes, stashes, other devs' namespaces, who knows).

  • git clone origin-url (non-bare): you will get all of the tags copied, a local branch master (HEAD) tracking a remote branch origin/master, and remote branches origin/next, origin/pu, and origin/maint. The tracking branches are set up so that if you do something like git fetch origin, they'll be fetched as you expect. Any remote branches (in the cloned remote) and other refs are completely ignored.

  • git clone --bare origin-url: you will get all of the tags copied, local branches master (HEAD), next, pu, and maint, no remote tracking branches. That is, all branches are copied as is, and it's set up completely independent, with no expectation of fetching again. Any remote branches (in the cloned remote) and other refs are completely ignored.

  • git clone --mirror origin-url: every last one of those refs will be copied as-is. You'll get all the tags, local branches master (HEAD), next, pu, and maint, remote branches devA/master and devB/master, other refs refs/foo/bar and refs/foo/baz. Everything is exactly as it was in the cloned remote. Remote tracking is set up so that if you run git remote update all refs will be overwritten from origin, as if you'd just deleted the mirror and recloned it. As the docs originally said, it's a mirror. It's supposed to be a functionally identical copy, interchangeable with the original.

这篇关于git clone --mirror和git clone --bare有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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