Forked from magnetikonline/gittruncatehistory.sh
Last active
August 29, 2015 14:27
-
-
Save stephen-james/7165e303923e4caca95e to your computer and use it in GitHub Desktop.
Truncate Git history to a specific SHA1, dropping everything before it.
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 | |
# Lifted from: https://github.com/adrienthebo/git-tools/blob/master/git-truncate | |
# Note: seem to be finding the need to run this twice over to commit the truncate | |
if [ -z "$1" -o -z "$2" ]; then | |
echo "Usage: $0 <drop before SHA1 commit> <branch>" | |
exit | |
fi | |
git filter-branch --parent-filter "sed -e 's/-p $1[0-9a-f]*//'" \ | |
--prune-empty \ | |
-- $2 | |
git for-each-ref --format="%(refname)" refs/original | \ | |
while read REFNAME; do | |
echo $REFNAME | |
git update-ref -d "$REFNAME" | |
done | |
git reflog expire --expire=0 --all | |
git repack -ad | |
git prune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment