Skip to content

Instantly share code, notes, and snippets.

@c9s
Created September 14, 2013 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9s/6561791 to your computer and use it in GitHub Desktop.
Save c9s/6561791 to your computer and use it in GitHub Desktop.
Script to truncate git history.
#!/bin/bash
rev=$1
if [[ -z $rev ]] ; then
echo "[rev] is required."
exit
fi
# create history branch from $rev
git branch history $rev
parent_rev=`git rev-parse $rev~1`
combined_rev=`echo '[Truncated history]' | git commit-tree "$parent_rev^{tree}"`
git rebase --onto $combined_rev $parent_rev
echo "Now you can push history branch to remote."
@c9s
Copy link
Author

c9s commented Sep 14, 2013

Usage:

Truncate history from rev 984503ec73:

 git-truncate-history 984503ec73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment