Skip to content

Instantly share code, notes, and snippets.

@s4parke
Created February 18, 2015 16:33
Show Gist options
  • Save s4parke/79f09b52ff92e5f33989 to your computer and use it in GitHub Desktop.
Save s4parke/79f09b52ff92e5f33989 to your computer and use it in GitHub Desktop.
Simple bash script for truncating git repo history
#!/bin/bash
# Usage:
# ./git-truncate.sh SHA1
# Removes all the history prior to commit "SHA1"
git checkout --orphan temp $1
git commit -m "Truncated history of git repo"
git rebase --onto temp $1 master
git branch -D temp
# Optional, may take awhile
git prune --progress
git gc --aggressive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment