我怎样才能清理我的.git文件夹?清理了我的项目目录,但.git仍然很庞大 [英] How can I clean my .git folder? Cleaned up my project directory, but .git is still massive

查看:610
本文介绍了我怎样才能清理我的.git文件夹?清理了我的项目目录,但.git仍然很庞大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在删除数百兆字节的意外生成的垃圾后,我的rails项目目录中的 .git / objects 仍然很庞大。

我试过 git add -A ,以及其他命令来更新索引并删除不存在的文件。我可能不正确地收集目录中具有两个字符名称的文件是blob。我试着回滚到之前的提交,但没有运气。



我可以做些什么来清理这个目录?

解决方案


  • 如果您添加了文件然后将其删除,斑点仍然存在但是悬空。 git fsck 会列出无法访问的blob, git prune 会删除它们。


  • 如果你添加了这些文件,提交了它们,然后回滚了 git reset --hard HEAD ^ ,它们会被卡住一点点。 git fsck 不会列出任何悬而未决的提交或blob,因为您的分支的 reflog 正在抓住他们。这里有一种方法可以确保只保留历史记录中的对象:

      git reflog expire --expire = now  - -all 
    git repack -ad#从packfiles中移除悬挂对象
    git prune#移除悬挂的松散对象


  • 另一种方法是克隆存储库,因为它只包含可访问的对象。但是,如果悬挂的对象被打包(如果执行了很多操作,git可能会自动打包),那么本地克隆将包含整个packfile:

      git clone foo bar#bad 
    git clone --no-hardlinks foo bar#also bad

    你必须指定一个协议来强制git来计算一个新的包:

      git clone file :// foo bar#good 



The .git/objects in my rails project directory is still massive, after deleting hundreds of Megabytes of accidentally generated garbage.

I have tried git add -A, as well as other commands to update the index and remove nonexistent files. I gather, perhaps incorrectly, that the files with two character names in the directory are blobs. I have tried rolling back to previous commits, but no luck.

What can I do to clean this directory?

解决方案

  • If you added the files and then removed them, the blobs still exist but are dangling. git fsck will list unreachable blobs, and git prune will delete them.

  • If you added the files, committed them, and then rolled back with git reset --hard HEAD^, they’re stuck a little deeper. git fsck will not list any dangling commits or blobs, because your branch’s reflog is holding onto them. Here’s one way to ensure that only objects which are in your history proper will remain:

    git reflog expire --expire=now --all
    git repack -ad  # Remove dangling objects from packfiles
    git prune       # Remove dangling loose objects
    

  • Another way is also to clone the repository, as that will only carry the objects which are reachable. However, if the dangling objects got packed (and if you performed many operations, git may well have packed automatically), then a local clone will carry the entire packfile:

    git clone foo bar                 # bad
    git clone --no-hardlinks foo bar  # also bad
    

    You must specify a protocol to force git to compute a new pack:

    git clone file://foo bar  # good
    

这篇关于我怎样才能清理我的.git文件夹?清理了我的项目目录,但.git仍然很庞大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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