Created
November 5, 2024 07:40
-
-
Save zwimer/5669c7fd2bc5fe7485a7764f1e31b953 to your computer and use it in GitHub Desktop.
Truncate `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
#!/bin/bash -eux | |
# Where to truncate from | |
export HASH=my-hash | |
# Truncate history | |
git checkout --orphan temp "${HASH}" | |
git commit -m "Truncate History" | |
git rebase --onto temp "${HASH}" master | |
git branch -D temp | |
# Push | |
git push --force-with-lease | |
# Clean | |
git gc --aggressive --prune=now | |
git reflog expire --expire-unreachable=now --all | |
git gc --aggressive --prune=now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment