如何通过硬链接克隆本地回购

如何通过硬链接克隆本地回购

本文介绍了git克隆。如何通过硬链接克隆本地回购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地git仓库。我想通过硬链接文件在本地机器上克隆它以节省磁盘空间。我怎样才能做到这一点?

解决方案

一个Git仓库是通过简化 3种文件

$ ol

  • 类数据库对象 $ c> $ GIT_DIR / objects ):这些对象永远不会被修改,有些可以被添加,有些可以被删除,但是文件永远不会被修改。这意味着它们在许多克隆中可以完全相同。

  • 存储库特定的配置和状态 $ GIT_DIR ):这些文件包含特定于存储库的配置(例如, $ GIT_DIR / info / * 。它们还存储存储库状态,比如什么是已知分支,检出分支是什么等等。它们不能在存储库之间共享,否则将违反设计。


  • 工作副本文件或源代码 :这些文件大部分时间都是源代码,它们意味着不同于一个存储库另一个。它们很灵活并且有很大的改变(要么是因为你编码很多,要么是因为你改变了很多分支,或者两者都改变​​了分支)。

    事实上,唯一的不变的,而不是存储库特定的文件是 object 文件。如果可能的话,它们会自动被Git强制链接(即使没有指定 -l )。



    如果你想两个存储库在同一个驱动器上具有完全相同的状态和文件,那么您绝对应该创建一个符号链接。但是你不能硬连接配置文件和工作拷贝文件,因为它们变化太大,特定于存储库。


    I have a local git repository. I want to clone it on the local machine by hardlinked files to save disk space. How can I do it?

    解决方案

    a Git repository is made, by simplification, of 3 kind of files:

    1. Database-like objects ($GIT_DIR/objects): These objects are never modified, some can be added, some can be removed, but the files are never modified. It means that they can be exactly the same between many clones.

    2. repository-specific configuration and status ($GIT_DIR): These files contains configuration specific to the repository ($GIT_DIR/info/* for example). They also store the repository status, like what are the known branches, what is the checked-out branch, etc. They can't be shared between repository, or that would be against the design

    3. working copy files, or source: These files are most of the time your source code, they are meant to be different from one repository to another. They are flexible and change a lot (either because you code a lot, or because you switch branches a lot, or both).

    As a matter of fact, the only non-changing, not repository-specific files are object files. And these are automatically hard-linked by Git if possible (even without specifying -l).

    If you want two repositories on the same drive to have the exact same status and files, then you should definitely make a symbolic link. But you can't hard-link configuration and working copy files because they change too much and are specific to the repository.

    这篇关于git克隆。如何通过硬链接克隆本地回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-13 12:38