Created
January 8, 2018 15:18
-
-
Save PieterScheffers/47289da744446336741726b9d803fe87 to your computer and use it in GitHub Desktop.
Git - Remove pushed file or dir from git history
This file contains 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
# Remove file/folder from history | |
git filter-branch -f --tree-filter 'rm -rf vendor/gems' HEAD | |
# or | |
git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD | |
# Run git garbage collection | |
git reflog expire --expire=now --all | |
git gc --aggressive --prune=now | |
# overwrite remote | |
git push origin --force --all | |
git push origin --force --tags | |
# (On other clients) Get new commit history | |
# with outstanding work (commits): | |
git fetch origin | |
git rebase | |
git reflog expire --expire=now --all | |
git gc --aggressive --prune=now | |
# Without outstanding work (commits): | |
git fetch origin | |
# WARNING: can destroy unpublished data! | |
git reset --hard origin/master | |
git reflog expire --expire=now --all | |
git gc --aggressive --prune=now |
Author
PieterScheffers
commented
Jan 8, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment