转换Git仓库浅? [英] Converting git repository to shallow?
本文介绍了转换Git仓库浅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将已克隆的git存储库转换为浅存储库?
git存储库是通过脚本以外的脚本下载的,所以我不能做浅克隆。
这样做的原因是为了节省磁盘空间。 (是的,我的磁盘空间很短,所以即使浅储存库没有多少节省,但仍然需要。)
我已经试过了
git repack -a -d -f -depth = 1
但是这实际上使得存储库变大了。
解决方案我们说最早的提交你希望保留一个<1 code> c0ffee 。
$ b
- 创建一个新的空分支
- 签出树 >你想保留的最早的提交,而不用实际检出提交:
git checkout c0ffee - 。
(现在HEAD
仍然指向新的空分支,但是您的工作树和索引都看起来像c0ffee
) - 提交整个树:
git commit -m初始提交,从c0ffee复制
- 此时
git diff-tree newbranch c0ffee
不应该产生输出 - 它们有相同的树。 (或者,您可以执行git show -s c0ffee --format =%T
和git show -s newbranch --format =%T < )
git rebase --onto newbranch c0ffee master
git branch -d newbranch
git gc
How can I convert an already cloned git repository to a shallow repository?
The git repository is downloaded through a script outside of my control so I cannot do a shallow clone.
The reason for doing this is to save disk space. (Yes, I'm really short on disk space so even though a shallow repository doesn't save much, it is needed.)
I already tried
git repack -a -d -f -depth=1
But that actually made the repository larger.
解决方案
Let's say the earliest commit you want to keep has a SHA1 of c0ffee
.
- Create a new empty branch
- Checkout the tree of the earliest commit you want to keep, without actually checking out the commit:
git checkout c0ffee -- .
(NowHEAD
is still pointing to your new empty branch, but your working tree and index both look like the tree ofc0ffee
) - Commit the whole tree:
git commit -m "Initial commit, copied from c0ffee"
- At this point
git diff-tree newbranch c0ffee
should produce no output -- they have the same tree. (Alternatively, you could dogit show -s c0ffee --format=%T
andgit show -s newbranch --format=%T
and they should show the same hash.) git rebase --onto newbranch c0ffee master
git branch -d newbranch
git gc
这篇关于转换Git仓库浅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文