转换Git仓库浅? [英] Converting git repository to shallow?

查看:81
本文介绍了转换Git仓库浅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将已克隆的git存储库转换为浅存储库?



git存储库是通过脚本以外的脚本下载的,所以我不能做浅克隆。



这样做的原因是为了节省磁盘空间。 (是的,我的磁盘空间很短,所以即使浅储存库没有多少节省,但仍然需要。)



我已经试过了

  git repack -a -d -f -depth = 1 

但是这实际上使得存储库变大了。

解决方案

我们说最早的提交你希望保留一个<1 code> c0ffee 。


$ b


  1. 创建一个新的空分支

  2. 签出 >你想保留的最早的提交,而不用实际检出提交: git checkout c0ffee - 。(现在 HEAD 仍然指向新的空分支,但是您的工作树和索引都看起来像 c0ffee

  3. 提交整个树: git commit -m初始提交,从c0ffee复制

  4. 此时 git diff-tree newbranch c0ffee 不应该产生输出 - 它们有相同的树。 (或者,您可以执行 git show -s c0ffee --format =%T git show -s newbranch --format =%T < )
  5. git rebase --onto newbranch c0ffee master

  6. git branch -d newbranch

  7. 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.

  1. Create a new empty branch
  2. Checkout the tree of the earliest commit you want to keep, without actually checking out the commit: git checkout c0ffee -- . (Now HEAD is still pointing to your new empty branch, but your working tree and index both look like the tree of c0ffee)
  3. Commit the whole tree: git commit -m "Initial commit, copied from c0ffee"
  4. At this point git diff-tree newbranch c0ffee should produce no output -- they have the same tree. (Alternatively, you could do git show -s c0ffee --format=%T and git show -s newbranch --format=%T and they should show the same hash.)
  5. git rebase --onto newbranch c0ffee master
  6. git branch -d newbranch
  7. git gc

这篇关于转换Git仓库浅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆