Forked from magnetikonline/gittruncatehistory.sh
Last active
September 11, 2015 17:01
-
-
Save lpil/3415933898cb16ee3c97 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 -e | |
# 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) || (-z $2) ]]; then | |
echo "Usage: $(basename $0) <drop before SHA1 commit> <branch>" | |
exit 1 | |
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 | |
# success | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment