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.
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
git commit --amend
if it is your HEAD commit; another is git rebase --interactive
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With