Last active
January 6, 2017 04:27
-
-
Save haridas/0c90496f30eba0a72683d1682116de77 to your computer and use it in GitHub Desktop.
Remove old files completely from git history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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