当从本地文件系统请求克隆时,Git 假定 -l
,大概是为了加速克隆并节省磁盘空间。这种类型的克隆意味着什么?如果我两次克隆存储库然后提交一个,那么更改是否会在另一个克隆中可见?我想知道 Git 是否小心复制写入。如果原始存储库是只读的,那么这会给克隆带来问题吗?
最佳答案
git clone
联机帮助页说明了关于 -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.
这意味着您将获得所有 Git 对象的硬链接(hard link),这没有实际意义,因为这些对象无论如何都是不可变的,并且一旦创建 Git 就不会更新它们。您还可以获得 HEAD
和其他符号引用的实际副本,因此在一个存储库中对它们所做的更改将不会在其他存储库中看到。如果您提交更改,将在 .git/objects
下创建一些新对象,并且 HEAD
引用将更新为指向最新提交(这将是新创建的对象之一);不会更新现有对象,因此您不必担心硬链接(hard link)。
联机帮助页说明了一个含义,您可能会感兴趣:
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.
硬链接(hard link)的缺点是它们引用磁盘上相同的实际 inode,因此如果一个 Git 对象损坏,所有硬链接(hard link)到它的本地克隆都将有一个损坏的对象。如果没有硬链接(hard link),您将拥有所有对象的实际备份副本。
关于git - 本地克隆对 Git 有何影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13038819/