如何减少现有git克隆的深度

如何减少现有git克隆的深度

本文介绍了如何减少现有git克隆的深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个克隆人.我想减少历史记录,而不会从头开始以更小的深度进行克隆.工作示例:

I have a clone. I want to reduce the history on it, without cloning from scratch with a reduced depth. Worked example:

$ git clone [email protected]:apache/spark.git
# ...
$ cd spark/
$ du -hs .git
193M    .git

好的,不是这样,但是它将用于本次讨论.如果我尝试gc,它会变小:

OK, so that's not so but, but it'll serve for this discussion. If I try gc it gets smaller:

$ git gc --aggressive
Counting objects: 380616, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (278136/278136), done.
Writing objects: 100% (380616/380616), done.
Total 380616 (delta 182748), reused 192702 (delta 0)
Checking connectivity: 380616, done.
$ du -hs .git
108M    .git

尽管如此,它仍然很大(git pull表示它仍然可以推/拉到遥控器上).重新打包怎么样?

Still, pretty big though (git pull suggests that it's still push/pullable to the remote). How about repack?

$ git repack -a -d --depth=5
Counting objects: 380616, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (95388/95388), done.
Writing objects: 100% (380616/380616), done.
Total 380616 (delta 182748), reused 380616 (delta 182748)
Pauls-MBA:spark paul$ du -hs .git
108M    .git

是的,没有变小. --repack的深度与克隆的深度不同:

Yup, didn't get any smaller. --depth for repack isn't the same for clone:

$ git clone --depth 1 [email protected]:apache/spark.git
Cloning into 'spark'...
remote: Counting objects: 8520, done.
remote: Compressing objects: 100% (6611/6611), done.
remote: Total 8520 (delta 1448), reused 5101 (delta 710), pack-reused 0
Receiving objects: 100% (8520/8520), 14.82 MiB | 3.63 MiB/s, done.
Resolving deltas: 100% (1448/1448), done.
Checking connectivity... done.
Checking out files: 100% (13386/13386), done.
$ cd spark
$ du -hs .git
17M .git

Git pull说它仍然与遥控器保持同步,这没有让任何人感到惊讶.

Git pull says it's still in step with the remote, which surprises nobody.

好-那么如何将现有克隆更改为浅克隆,而又不对其进行新化和重新检出?

OK - so how to change an existing clone to a shallow clone, without nixing it and checking it out afresh?

推荐答案

git clone --mirror --depth=5  file://$PWD ../temp
rm -rf .git/objects
mv ../temp/{shallow,objects} .git
rm -rf ../temp

这实际上不是在从头开始"进行克隆,因为它纯粹是本地工作,它几乎只创建了浅化的压缩包文件,可能只有数十KB.我敢冒险您不会获得比这更高的效率,您将获得大量的自定义工作,这些自定义工作以脚本和测试工作的形式使用的空间比以kb临时回购开销的形式占用的空间更多.

This really isn't cloning "from scratch", as it's purely local work and it creates virtually nothing more than the shallowed-out pack files, probably in the tens of kbytes total. I'd venture you're not going to get more efficient than this, you'll wind up with custom work that uses more space in the form of scripts and test work than this does in the form of a few kb of temporary repo overhead.

这篇关于如何减少现有git克隆的深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:04