【问题标题】:Compact Git repository with history depth具有历史深度的紧凑型 Git 存储库
【发布时间】:2015-10-25 10:44:52
【问题描述】:

在 Git 中,有一个命令 git clone --depth=<depth> 可以仅检索特定长度的历史数据。还有一个命令可以使用git fetch --depth=<depth>收集更多的历史数据。

当我们想从大型存储库中释放一些空间时怎么样?我知道我们可以使用git gcgit prune,但是还有其他具体的方法,比如--depth=<depth> 来减少本地存储库中提交存储的数量吗?并且它还应该让 SHA1 能够继续使用它。

【问题讨论】:

    标签: git


    【解决方案1】:

    最简单的方法是:

    • 完全删除当前本地仓库
    • git clone --depth=n /url/of/remote/repo

    这将克隆最后 n 次提交,同时允许 fetch/pull/psuh 仍然可以使用远程 repo。

    从 Git 2.5 开始,您可以 fetch a single commit,但除非该提交是最新的提交(类似于 git clone --depth=1),否则不会分配给 fetch/pull/push。

    确保给定本地存储库尽可能精简的另一种方法是使用combination of gc/prune/repack

    git gc
    git repack -Ad      # kills in-pack garbage
    git prune           # kills loose garbage
    

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2014-01-16
      • 1970-01-01
      • 2022-08-07
      • 2017-06-23
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      相关资源
      最近更新 更多