In this article i am showing how to clear Git history by removing all commits. You may need this if you want to delete sensitive data from the history of Git commits. After such cleanup you will have the latest version of your Git repository, but with the one commit only. Be aware that after resetting all the history of changes in your Git repository will be deleted as well.
- 1. Create a temporary branch and checkout:
- 2. Add all files to the temporary branch and commit the changes:
- 3. Delete the master branch:
- 4. Rename the temporary branch to master:
- 5. Forcefully update the remote repository:
- Reference
1. Create a temporary branch and checkout:
git checkout --orphan temp_branch
2. Add all files to the temporary branch and commit the changes:
git add -A
git commit -am "The first commit after purge"
3. Delete the master branch:
git branch -D master
4. Rename the temporary branch to master:
git branch -m master
5. Forcefully update the remote repository:
git push -f origin master
Reference
KF