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


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

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

最佳答案 最简单的方法是:

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

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

从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
点赞