git clone --mirror 和 git clone --bare 有什么区别

git clone --mirror 和 git clone --bare 有什么区别

问题描述:

git clone 帮助页面有关于 --mirror 的说明:

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

设置远程仓库的镜像.这意味着 --bare.

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

但没有详细说明 --mirror 克隆与 --bare 克隆有何不同.

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

不同的是,当使用 --mirror 时,所有 refs 都被复制为 as-是.这意味着一切:远程跟踪分支、注释、refs/originals/*(来自过滤器分支的备份).克隆的 repo 拥有一切.它还设置为远程更新将从源重新获取所有内容(覆盖复制的引用).这个想法实际上是镜像存储库,拥有一个完整的副本,这样你就可以在多个地方托管你的*存储库,或者备份它.考虑直接复制 repo,除非以更优雅的 git 方式.

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:

--镜像

设置源存储库的镜像.这意味着 --bare.与 --bare 相比,--mirror 不仅将源的本地分支映射到目标的本地分支,还将所有 refs(包括远程分支、注释等)映射到目标的本地分支.) 并设置一个 refspec 配置,以便所有这些 ref 都被目标存储库中的 git remote update 覆盖.

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.

我原来的回答也指出了裸克隆和普通(非裸)克隆之间的区别——非裸克隆设置远程跟踪分支,只为HEAD创建一个本地分支,而裸克隆直接复制分支.

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.

假设 origin 有几个分支(master (HEAD)nextpumaint)、一些标签(v1v2v3)、一些远程分支(devA/masterdevB/master),以及其他一些参考资料(refs/foo/barrefs/foo/baz,可能是笔记、藏匿处、其他开发者的命名空间,谁知道).

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(非裸):您将复制所有标签,一个本地分支 master (HEAD) 跟踪远程分支 origin/master 和远程分支 origin/nextorigin/puorigin/维护.跟踪分支的设置是为了如果您执行诸如 git fetch origin 之类的操作,它们将按照您的预期被获取.任何远程分支(在克隆远程中)和其他引用都将被完全忽略.

  • 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: 你将复制所有标签,本地分支 master (HEAD)nextpumaint,无远程跟踪分支.也就是说,所有分支都按原样复制,并且设置完全独立,不期望再次获取.任何远程分支(在克隆远程中)和其他引用都将被完全忽略.

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: 这些引用中的每一个都将按原样复制.您将获得所有标签、本地分支 master (HEAD)nextpumaint,远程分支 devA/masterdevB/master,其他 refs refs/foo/barrefs/foo/baz>.一切都与克隆遥控器中的完全一样.远程跟踪设置为,如果您运行 git remote update,所有引用都将从原点覆盖,就像您刚刚删除镜像并重新克隆它一样.正如文档最初所说,它是一面镜子.它应该是功能相同的副本,可与原件互换.

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.