Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the size of a repo on Github

Tags:

git

github

I accidentally committed some large test wav files into my repository and they are using up a lot of space on my Github account. How can I remove these files from the history?

Note: these files were committed some time ago and are not on the HEAD commit.

like image 330
Corban Brook Avatar asked Oct 20 '09 19:10

Corban Brook


2 Answers

There's no way to remove them without modifying the history, so if anyone's pulled the changes, you may have to deal with that mess - see recovering from upstream rebase in man git-rebase. This can be pretty bad, depending on your workflow - one way or another you'll probably have to make everyone aware that they need to switch to the "new" master branch, rebasing any work in progress on top of it.

If the commit were still on the tip, you could reset to the commit before it:

git reset --hard HEAD^

or amend it:

git rm test.wav
git commit --amend

But since it's no longer at the tip, your best bet is probably to probably do it with an interactive rebase:

git rebase -i <commit-before-mistake>

Change "pick" to "edit" on the commit you want to fix, then have at it! (or even remove the whole commit if that's okay)*

After you finish doing whichever of these you pick, you'll have to force the push, since it's no longer a fast-forward:

git push -f origin

* If you've subsequently committed modifications to these files, you'll get issues as you continue on in the rebase. They should be straightforward to deal with, since you just want the files gone. Of course, if there've been a hundred commits since then that'll all cause conflicts, you could have a look at git-filter-branch. The relevant example from the man page is:

git filter-branch --index-filter ’git rm --cached --ignore-unmatch filename’ HEAD

like image 180
Cascabel Avatar answered Sep 24 '22 04:09

Cascabel


  1. Remove it from your local history on the branch where you committed it. One way to do that is using git commit --amend if it is your HEAD commit; another is git rebase --interactive.
  2. Force push the updated branch to github.

    git push --force github
    

    (where github is the name of your remote for GitHub).

This will remove it from the active history. To actually reclaim the space, GitHub will need to do a garbage collection. I'm not sure a way to do that explicitly, if they don't do it automatically. You may need to file a support request.

like image 35
Emil Sit Avatar answered Sep 26 '22 04:09

Emil Sit