Skip to content

Instantly share code, notes, and snippets.

@haridas
Last active January 6, 2017 04:27
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 haridas/0c90496f30eba0a72683d1682116de77 to your computer and use it in GitHub Desktop.
Save haridas/0c90496f30eba0a72683d1682116de77 to your computer and use it in GitHub Desktop.
Remove old files completely from git history
## How to remove the old files/folder from all git commits.
#1. clone the repo freshly
git clone <repo.git>
#2. Do index-filter option to go through all the object indexs and look for give match
# And remove those matching objects.
git filter-branch \
--prune-empty \
--index-filter \
'git rm -rf --cached --ignore-unmatch <YOUR_FILE_OR_FOLDER_TO_BE_REMOVED>' \
--tag-name-filter cat -- --all
# 3. As git won't remove those objects really, it does unlink from the history.
# We can avoid those removed object by cloning the repo again. Clone operation
# Won't download the removed objects.
git clone file:///<path_to_repo> <repo-trimmed>
# 4. Create a new project in github / other providers and push this new project on it.
# As pushing to old repo itself won't remove the removed / unlinked objects.
# Git is trying to keep the objects as much as possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment