git clone / push / pull是否反映了所涉及回购的确切内容? [英] Does a git clone/push/pull mirror the exact contents of the repos involved?

查看:107
本文介绍了git clone / push / pull是否反映了所涉及回购的确切内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何提出问题,如果不清楚,请致歉。如果你的 git clone 有一堆悬挂对象的回购,你会克隆那些吗?相反。如果你做了一个 git gc 并推送给其他人,他们的repo会丢失任何 git gc 会清理掉的东西

我猜这些都不会发生,但我找不到任何有关此场景的文档。



我发现一些信息,似乎暗示大多数协议 git clone 为您提供了一个干净的repo,但是如果您使用文件路径指定文件,它将复制所有内容。

 指定file://前缀的主要原因是,如果您想要
存储库的干净副本,并省略无关的引用或对象。


解决方案

Git克隆不会克隆悬空对象。



当您推送它时,您的 git gc 不会以任何方式影响远程回购,除非您的推送引起悬挂对象,然后在远程运行 git gc 以删除它们。



除非......



这是一个共享克隆(由 - 共享 -s flag)或本地克隆( - local -l <​​/ code>)。从文档:


-l <​​/ p>

当要从中克隆的存储库是在本地机器上,这个标志
绕过了正常的git aware传输机制,并通过复制 HEAD以及对象和
引用目录下的所有内容来克隆
存储库。 STRONG>。在可能的情况下,.git / objects /目录下的文件是
硬链接以节省空间。当
源存储库使用/ path / to / repo语法指定时,这是默认设置,所以它
本质上是一个无操作选项。要强制拷贝而不是硬连接
(如果你试图备份你的
仓库,这可能是可取的),但仍然避免使用通常的git aware传输
机制, - 可以使用no-hardlinks。



-s



当要克隆的存储库位于本地机器,而不是
使用硬链接,自动设置.git / objects / info / alternates到
与源存储库共享对象。生成的存储库
首先没有任何对象。



注意:这是一个可能危险的操作;除非
你明白它的作用,否则不要使用它。如果你使用这个
选项克隆你的仓库,然后在源仓库中删除分支(或使用任何其他的git命令,使
使任何现有的未提交的commit),那么一些
对象可能会变成未引用(或悬挂)。这些对象可能是由
自动调用git gc --auto
的普通git操作(例如git commit)删除的。

所以当你做一个 git clone / path / to / repo 时,你正在复制对象(或者创建硬链接),你将得到在这种情况下悬挂的物体。在其他情况下(使用git协议,ssh,文件协议等),你永远不会得到克隆中的悬挂对象。



在这里寻找交通发生的方式 - a href =http://progit.org/book/ch9-6.html =nofollow noreferrer> http://progit.org/book/ch9-6.html


I wasn't sure how to word the question, so apologies if it's not clear. If you git clone a repo that had a bunch of dangling objects, do you clone those? Same for the opposite. If you did a git gc and pushed that to someone else, does their repo lose anything the git gc would have cleaned up?

I would guess that neither of these would occur, but I can't find any documentation on this scenario.

I found some information that seems to imply that with most protocols git clone gives you a clean repo, but if you specify the file using a file path it copies everything.

The main reason to specify the file:// prefix is if you want a clean copy of the
repository with extraneous references or objects left out.

解决方案

Git clone doesn't clone dangling objects.

And your git gc will not in any way affect the remote repo when you push to it, unless your push causes dangling objects and then a git gc is run on remote to remove those.

Unless....

It was a shared clone ( specified with the --shared or -s flag) or a local clone (--local or -l). From the docs:

-l

When the repository to clone from is on a local machine, this flag bypasses the normal "git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. The files under .git/objects/ directory are hardlinked to save space when possible. This is now the default when the source repository is specified with /path/to/repo syntax, so it essentially is a no-op option. To force copying instead of hardlinking (which may be desirable if you are trying to make a back-up of your repository), but still avoid the usual "git aware" transport mechanism, --no-hardlinks can be used.

-s

When the repository to clone is on the local machine, instead of using hard links, automatically setup .git/objects/info/alternates to share the objects with the source repository. The resulting repository starts out without any object of its own.

NOTE: this is a possibly dangerous operation; do not use it unless you understand what it does. If you clone your repository using this option and then delete branches (or use any other git command that makes any existing commit unreferenced) in the source repository, some objects may become unreferenced (or dangling). These objects may be removed by normal git operations (such as git commit) which automatically call git gc --auto.

So when you do a git clone /path/to/repo you are copying the objects ( or creating hardlinks) and you will get the dangling object in this case. In other cases ( using git protocols, ssh, file protocol etc. ) you will never get the dangling objects in the clone.

Look here for how the transport happens - http://progit.org/book/ch9-6.html

这篇关于git clone / push / pull是否反映了所涉及回购的确切内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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