Last active
September 28, 2018 07:43
-
-
Save syntaxval/2d29ea4cf00040cb869f05e47e5e8ac8 to your computer and use it in GitHub Desktop.
Git History Rewrite
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 | |
git filter-branch --tree-filter 'rm path/to/file' HEAD | |
# Remove directory | |
git filter-branch --tree-filter 'rm -rf path/to/directory' --prune-empty HEAD | |
# Replace a file | |
git filter-branch --tree-filter 'cp /absolute/path/to/file path/to/file' HEAD | |
# GPG sign all rewritten history. | |
git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all | |
# Cleanup | |
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
# Force commit after history has been rewriten. | |
git push origin master --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference: https://murze.be/how-to-remove-a-big-file-wrongly-committed-to-a-git-repo