- Check out the branch you want to truncate.
- Get the SHA1 hash of the commit in that branch you want to start history.
truncate.sh SHA1 branchname
liketruncate.sh 01cea49c9cbefd696bbd54ee41b47cbf1b6d1bd5 master
- Get the SHA1 hash of the new base commit.
- Get the date you want that commit to have in the format like
Sat, 14 Dec 2013 12:40:00 -0800
fixdate.sh SHA1 "date"
likefixdate.sh c776e91dd573053ec09ecb1b0737909f9aacd0c9 "Sat, 14 Dec 2013 12:40:00 -0800"
- Add a remote to the new repo.
- Push the updated branch to the remote.
Created
March 16, 2017 21:45
-
-
Save tillig/d5c606d7000cc7d8f187de45c67c6353 to your computer and use it in GitHub Desktop.
Truncate Git repo history, back-date initial commit, push to new repo
This file contains hidden or 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 | |
git filter-branch --env-filter \ | |
"if test \$GIT_COMMIT = '$1' | |
then | |
export GIT_AUTHOR_DATE='$2' | |
export GIT_COMMITTER_DATE='$2' | |
fi" && rm -fr "$(git rev-parse --git-dir)/refs/original/" |
This file contains hidden or 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 | |
git checkout --orphan temp $1 | |
git commit -m "Truncated history." | |
git rebase --onto temp $1 $2 | |
git branch -D temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment