Compact Git存储库,具有历史深度

时间:2015-08-03 10:51:02

标签: git

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

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

1 个答案:

答案 0 :(得分:2)

最简单的方法是:

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

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

从Git 2.5开始,你可以fetch a single commit,但除非那个提交是最新的(类似于git clone --depth=1),否则不会提取/拉/推。

确保给定本地回购尽可能精益的另一种方法是使用combination of gc/prune/repack

git gc
git repack -Ad      # kills in-pack garbage
git prune           # kills loose garbage
相关问题