SysTutorials Forums QA How to clean the commit history of a repository?

Tagged: 

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 12 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.

git commit

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
Reply To: How to clean the commit history of a repository?
Your information:





<a href="" title="" rel="" target=""> <blockquote cite=""> <code> <pre> <em> <strong> <del datetime=""> <ul> <ol start=""> <li> <img src="" border="" alt="" height="" width="">

Please share if you like this post: