git clone --mirror 和 git clone --bare 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3959924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between git clone --mirror and git clone --bare
提问by Sam
The git clone help page has this to say about --mirror
:
git clone 帮助页面有这样的说法--mirror
:
Set up a mirror of the remote repository. This implies
--bare
.
设置远程存储库的镜像。这意味着
--bare
.
But doesn't go into detail about how the --mirror
clone is different from a --bare
clone.
但没有详细说明--mirror
克隆与克隆有何不同--bare
。
回答by Cascabel
The difference is that when using --mirror
, allrefs 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.
不同之处在于,在使用时--mirror
,所有引用都按原样复制。这意味着一切:远程跟踪分支、注释、参考/原始文件/*(来自过滤器分支的备份)。克隆的 repo 拥有一切。它还设置为远程更新将从源重新获取所有内容(覆盖复制的引用)。这个想法实际上是镜像存储库,有一个完整的副本,这样你就可以在多个地方托管你的中央存储库,或者备份它。想想直接复制 repo,除了以更优雅的 git 方式。
The new documentationpretty 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 agit remote update
in the target repository.
--mirror
设置源存储库的镜像。这意味着
--bare
. 与 相比--bare
,--mirror
不仅将源的本地分支映射到目标的本地分支,它还映射所有引用(包括远程分支、注释等)并设置 refspec 配置,以便所有这些引用都被git remote update
目标存储库中的a 覆盖.
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.
我最初的回答还指出了裸克隆和普通(非裸)克隆之间的区别——非裸克隆设置远程跟踪分支,只为 建立一个本地分支HEAD
,而裸克隆直接复制分支。
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).
假设 origin 有几个分支(master (HEAD)
、next
、pu
、 和maint
)、一些标签(v1
、v2
、v3
)、一些远程分支(devA/master
、devB/master
)和一些其他参考(refs/foo/bar
、refs/foo/baz
,可能是笔记、藏匿处、其他开发人员的命名空间,谁知道)。
git clone origin-url
(non-bare):You will get all of the tags copied, a local branchmaster (HEAD)
tracking a remote branchorigin/master
, and remote branchesorigin/next
,origin/pu
, andorigin/maint
. The tracking branches are set up so that if you do something likegit 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 branchesmaster (HEAD)
,next
,pu
, andmaint
, 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 branchesmaster (HEAD)
,next
,pu
, andmaint
, remote branchesdevA/master
anddevB/master
, other refsrefs/foo/bar
andrefs/foo/baz
. Everything is exactly as it was in the cloned remote. Remote tracking is set up so that if you rungit 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 origin-url
(非裸):您将得到所有复制的标签,一个本地分支master (HEAD)
追踪远程分支origin/master
和远程分支origin/next
,origin/pu
和origin/maint
。设置跟踪分支,以便如果您执行类似的操作git fetch origin
,它们将按您的预期被获取。任何远程分支(在克隆的远程中)和其他引用都被完全忽略。git clone --bare origin-url
:您将获得全部复制的标签,地方分支机构master (HEAD)
,next
,pu
,和maint
,没有远程跟踪分支。也就是说,所有分支都按原样复制,并且设置完全独立,不期望再次获取。任何远程分支(在克隆的远程中)和其他引用都被完全忽略。git clone --mirror origin-url
:这些参考中的每一个都将按原样复制。你会得到所有的标签,地方分支机构master (HEAD)
,next
,pu
,和maint
,远程分支机构devA/master
和devB/master
其他裁判refs/foo/bar
和refs/foo/baz
。一切都与克隆遥控器中的完全一样。设置了远程跟踪,因此如果您运行git remote update
所有引用,将从原点覆盖所有引用,就像您刚刚删除镜像并重新克隆它一样。正如文档最初所说,它是一面镜子。它应该是功能相同的副本,可与原件互换。
回答by hfs
$ git clone --mirror $URL
is a short-hand for
是一个简写
$ git clone --bare $URL
$ (cd $(basename $URL) && git remote add --mirror=fetch origin $URL)
(Copied directly from here)
(直接从这里复制)
How the current man-page puts it:
当前手册页如何放置它:
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 agit remote update
in the target repository.
与 相比
--bare
,--mirror
不仅将源的本地分支映射到目标的本地分支,它还映射所有引用(包括远程分支、注释等)并设置 refspec 配置,以便所有这些引用都被git remote update
目标存储库中的a 覆盖.
回答by Mark E. Hamilton
My tests with git-2.0.0 today indicate that the --mirror option does not copy hooks, the config file, the description file, the info/exclude file, and at least in my test case a few refs (which I don't understand.) I would not call it a "functionally identical copy, interchangeable with the original."
我今天对 git-2.0.0 的测试表明 --mirror 选项不会复制钩子、配置文件、描述文件、信息/排除文件,至少在我的测试用例中没有复制一些引用(我不不明白。)我不会称它为“功能相同的副本,可与原版互换”。
-bash-3.2$ git --version
git version 2.0.0
-bash-3.2$ git clone --mirror /git/hooks
Cloning into bare repository 'hooks.git'...
done.
-bash-3.2$ diff --brief -r /git/hooks.git hooks.git
Files /git/hooks.git/config and hooks.git/config differ
Files /git/hooks.git/description and hooks.git/description differ
...
Only in hooks.git/hooks: applypatch-msg.sample
...
Only in /git/hooks.git/hooks: post-receive
...
Files /git/hooks.git/info/exclude and hooks.git/info/exclude differ
...
Files /git/hooks.git/packed-refs and hooks.git/packed-refs differ
Only in /git/hooks.git/refs/heads: fake_branch
Only in /git/hooks.git/refs/heads: master
Only in /git/hooks.git/refs: meta
回答by Feckmore
A nuanced explanation from the GitHub documentation on Duplicating a Repository:
GitHub 文档中关于Duplicating a Repository 的细致解释:
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository.
与裸克隆一样,镜像克隆包含所有远程分支和标签,但每次获取时所有本地引用都将被覆盖,因此它始终与原始存储库相同。
回答by PaulMurrayCbr
A clone copies the refs from the remote and stuffs them into a subdirectory named 'these are the refs that the remote has'.
克隆从远程复制引用并将它们塞入名为“这些是远程拥有的引用”的子目录中。
A mirror copies the refs from the remote and puts them into its own top level - it replaces its own refs with those of the remote.
镜像从远程复制引用并将它们放入自己的顶层 - 它用远程的引用替换自己的引用。
This means that when someone pulls from your mirror and stuffs the mirror's refs into thier subdirectory, they will get the same refs as were on the original. The result of fetching from an up-to-date mirror is the same as fetching directly from the initial repo.
这意味着当有人从您的镜像中取出并将镜像的 ref 塞入他们的子目录时,他们将获得与原始镜像相同的 ref。从最新镜像中获取的结果与直接从初始存储库中获取的结果相同。
回答by yanzi1225627
I add a picture, show config
difference between mirror and bare.
The left is bare, right is mirror. You can be clear, mirror's config file have
fetch
key, which means you can update it,by git remote update
or git fetch --all
我添加了一张图片,显示config
了镜像和裸机之间的区别。
左边是裸露的,右边是镜子。你可以清楚,镜像的配置文件有
fetch
密钥,这意味着你可以更新它,通过git remote update
或git fetch --all
回答by Shantanu Singh
$ git clone --bare https://github.com/example
This command will make the new itself the $GIT_DIR. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping. When this option is used, neither remote-tracking branches nor the related configuration variables are created.
此命令将使新本身成为 $GIT_DIR。远程的分支头也直接复制到相应的本地分支头,无需映射。使用此选项时,既不会创建远程跟踪分支,也不会创建相关的配置变量。
$ git clone --mirror https://github.com/example
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references (including remote-tracking branches, notes etc.) will be overwritten each time you fetch, so it will always be the same as the original repository.
与裸克隆一样,镜像克隆包含所有远程分支和标签,但每次获取时都会覆盖所有本地引用(包括远程跟踪分支、注释等),因此它始终与原始存储库相同.