从git / github中删除不需要的文件 [英] Removing unwanted files from git/github

查看:201
本文介绍了从git / github中删除不需要的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我早些时候推动了很多文件git,其中许多是不需要的。我遵循以下步骤删除那些不需要的文件(jar / lib / ide文件等)。

删除文件 - 1

删除文件 - 2



基本上我做了,

  git filter-branch -f --index-filter'git rm --cached --ignore-不匹配的目标'

我在github中验证这些文件不再存在。当我在github下载我的repo时,其小于1MB,但是当我做git clone时,它仍然是100MB。



经过克隆后的进一步研究,

MyRepo / .git / objects /pack/pack-b6b2b82ecd58c551c3648b9ca97e4f8b29rrt3c2.pack 99.8 MB 。我怎么能摆脱这个?

解决方案

这听起来像你错过了第一个链接(第9步):

  git for-each-ref --format ='delete%(refname)'refs / original | git update-ref --stdin 
git reflog expire --expire = now --all
git gc --prune = now

git gc 垃圾收集。



你应该确保你不会不小心 git push 返回臃肿的内容。



您建议的第二个链接几乎完全处理从存储库中删除文件作为提交;如果你这样做,你仍然可以在提交之前检出一个修订版本,所以文件的内容显然仍然在某处,因此你的 git clone 会不会减小尺寸。


I earlier pushed many files to git, many of them where unwanted. I followed the following to remove those unwanted files (jar/lib/ide files etc).

Remove Files - 1

Remove Files - 2

Basically I did,

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch target'

I verified in github those files don't exist anymore. When I download my repo as zip in github its less than 1MB, however when I do a git clone, its still 100MB.

Upon further research I found after cloning,

MyRepo/.git/objects/pack/pack-b6b2b82ecd58c551c3648b9ca97e4f8b29rrt3c2.pack is 99.8 MB. How can I get rid of this?

解决方案

It sounds like you missed the last step of the first link (step 9):

git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now

The git gc garbage collects.

I'd add that you should make sure you do not accidentally git push back the bloated content. I suggest removing local copies of all repositories and recloning once you are sure it works.

The second link you suggested almost entirely deals with removing the file from the repository as a commit; if you do this, you will still be able to check out a revision prior to the commit, so the contents of the file must obviously still be somewhere, hence your git clone does not reduce in size.

这篇关于从git / github中删除不需要的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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