Skip to content

Instantly share code, notes, and snippets.

@claudius108
Forked from stephenhardy/git-clearHistory
Last active May 10, 2023 16:59
Show Gist options
  • Save claudius108/9eac962ed015c69baa28a2f9ca7931f5 to your computer and use it in GitHub Desktop.
Save claudius108/9eac962ed015c69baa28a2f9ca7931f5 to your computer and use it in GitHub Desktop.
Steps to clear out the history of a git/github repository

RECREATE A REPO WITH ONLY THE CONTENT

Remove the history

rm -rf .git

recreate the repo from the current content only

git init git add . git commit -m "Initial commit"

push to the github remote repos ensuring you overwrite history

git remote add origin git@github.com:/.git git push -u --force origin master

RESTORE FILE DELETED SOME COMMITS ABACK

get a file with all the deleted files

git log --diff-filter=D --summary > deleted-files.txt

restore a file

git checkout ~1 <path/to/file>

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