Skip to content

Instantly share code, notes, and snippets.

@filipechagas
Created August 26, 2020 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipechagas/5162e37f01792ece1ba9812d10ef37ce to your computer and use it in GitHub Desktop.
Save filipechagas/5162e37f01792ece1ba9812d10ef37ce to your computer and use it in GitHub Desktop.
Git filter-branch

Git filter-branch

So today I noticed my git repository was taking too much disk space and discovered it was due to bundler caching gems. At first I thought I'd just remove vendor/cache directory it be done with it. But that's not how git works, is it?

That's how I came across git filter-branch.

The following command will remove the vendor/cache directory and all its references throughout your repository history.

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch -r vendor/cache"

Undoing it

And, should you realise you shouldn't have done that, git is also there for you. Whenever you use filter-branch, git creates a backup of the previous state for you at .git/refs/original/refs/heads/NAME_OF_YOUR_BRANCH. Meaning all you have to do is run:

git reset --hard refs/original/refs/heads/NAME_OF_YOUR_BRANCH

You're welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment