How to clean the commit history of a repository in both of my locally cloned copy and the copy on the git server so that only the files after the last commit are left?
- This topic was modified 1 year, 7 months ago by Admins.
git works in branches. Here, we assume removing the history of the master branch. One solution is doing as follows.
Rename the current master.
git checkout --orphan newbranch
Add all files back. If you would add only some files, add them separately.
git add -A
Commit the change of adding files.
Delete the master branch.
git branch -D master
Rename the current
newmaster branch to be master.
git branch -m master
Force pushing the master branch to the git server.
git push -f origin master
(Optional) Let git garbage collect unnecessary files in the local repository
git gc --aggressive --prune=all