git gc --aggressive --prune = all不会从存储库中删除大文件 [英] git gc --aggressive --prune=all does not remove big file from repository

查看:2207
本文介绍了git gc --aggressive --prune = all不会从存储库中删除大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于如何从回购中删除意外添加的大文件的SO问题,其中许多人建议使用 git gc 命令。但是,我发现它不适合我,我现在不会出现什么问题。

There are many SO questions regarding "how to remove an accidentally added big file from repo", many of them suggesting using git gc command. However, I find it not working for me and I don't now what's going wrong.

这是我所做的:

Here is what I have done:

$ git init
Initialized empty Git repository in /home/wzyboy/git/myrepo/.git/
$ echo hello >> README
$ git add README 
$ git commit -a -m 'init commit'
[master (root-commit) f21783f] init commit
 1 file changed, 1 insertion(+)
 create mode 100644 README
$ du -sh .git
152K    .git
$ cp ~/big.zip .
$ git add big.zip 
$ git commit -a -m 'adding big file'
[master 3abd0a4] adding big file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big.zip
$ du -sh .git
77M .git
$ git log --oneline 
3abd0a4 adding big file
f21783f init commit
$ git reset --hard f21783f
HEAD is now at f21783f init commit
$ git log --oneline 
f21783f init commit
$ git gc --aggressive --prune=all
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), done.
Total 6 (delta 0), reused 0 (delta 0)
$ git gc --aggressive --prune=now
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), done.
Total 6 (delta 0), reused 6 (delta 0)
$ du -sh .git
77M .git
$ git version
git version 2.2.2

在上面的控制台输出中,我创建了一个新的git仓库,添加了一个小文本文件, code> .git 目录的大小为152K,迄今为止非常好。然后我在回购中添加了一个大文件,目录膨胀到77M。但是,在我试图删除大文件( git reset --hard git rebase -i )后,我无论如何运行 git gc 具有不同的选项,都无法恢复大文件所声明的磁盘空间。

In the console output above, I created a new git repo, added one small text file and the .git directory is 152K in size, so far so good. Then I added a big file into the repo and the directory bloats to 77M. However, aftering my attempting to remove the big file (git reset --hard or git rebase -i), I cannot recover the disk space claimed by the big file, no matter how I run git gc with different options.

任何人都可以告诉我为什么 git gc 在我的情况下不起作用?我应该如何恢复磁盘空间?是否可以使用 git gc 而不是 git filter-branch

Could any one tell me why git gc does not work in my case? What should I do to recover the disk space? Is it possible to recover the disk space using git gc instead of git filter-branch?

谢谢。

推荐答案

git reflog expire --expire=now --all
git gc --aggressive --prune=now

这将删除所有reflogs,请谨慎使用。

This will remove all the reflogs, so use with caution.

这篇关于git gc --aggressive --prune = all不会从存储库中删除大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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