8

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.

2
  • The real issue here is probably going to be rewriting history that others have already pulled - there are a lot of posts here as well as things you can find with google dealing with that particular problem, besides the man page section I mentioned in my answer. Commented Oct 20, 2009 at 19:34
  • 1
    Well currently I am the only committer on the project so it makes things a little easier in that regard. Commented Oct 21, 2009 at 0:10

2 Answers 2

11

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 

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

GitHub garbage collects after every repository operation.
@JörgWMittag - are you sure about that? I pushed branches after cleaning them from old large files and on github my repo is still the same size. locally the repo has shrunk.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.