git clone --mirror 和 bare repo 的简单副本有什么区别

What is the difference between git clone --mirror and a simple copy of a bare repo

假设我想复制一个裸存储库。我想备份它。似乎规范的方法是使用 git clone --mirror。但是,您似乎也可以使用 OS(例如 cp -r bare_repo bare_repo_bkp)复制裸存储库。

git clone --mirror 与使用 OS 的递归复制到底有什么不同,使用其中一种更合适还是更不合适?

我将首先引用我书中的边注(我需要回去继续工作):

In fact, there is a fairly close relationship between system backups and version control. The key difference between the two is a function of their purpose.

Backups aim to allow you to restore anything—one file, many files, or even the entire system—after some kind of error or disaster, including loss of storage media. Backups therefore tend to be performed on a time schedule, such as hourly, daily, weekly, and so on. When backups are aimed at disaster recovery, we may delete intermediate versions, e.g., discard all hourly backups after a daily backup, then discard all daily backups after a weekly backup. In other words, backups are usually made with a system-driven point of view.

Version control systems, by contrast, aim to allow you to view or restore files from a user- and/or project-driven point of view. New versions are entered at check-in or commit time. We’ll see more about this below. If discarding old versions is allowed at all, it is also normally done with specific care, rather than according to a time schedule.

If you make backups at well-chosen times, and keep those backups forever, this does result in a form of version control. Management and comparisons of versions may prove difficult, though.

更具体地说,git clone 制作了一个存储库的 克隆 ,而不是备份; cp -r 进行备份(无论如何在正确的条件下)。不同之处在于,克隆通常会复制所有 commits,但不会复制某些非 commit-y 项目,包括但不一定限于这些:

  • 引用,除非你使用--mirror;1
  • reflogs(即使 --mirror);
  • 配置值和挂钩。

由于 reflogs 保留名义上删除的提交,因此克隆通常也会忽略这些提交。这通常被认为是积极的,但出于备份目的,可能被认为是消极的。


1一个非镜像克隆将另一个 Git 的分支引用变成远程跟踪名称。但是,它确实会复制标记名称以及复制的标记对象(通常是提交和带注释的标记对象),前提是这是一个完整的克隆而不是一个浅表。