Search code examples
gitrebase

Edit git remote log history


I did several git reverts and pushed to remote branch(meaning revert a commit and then revert revert...), which looks pretty annoying. I want to clean my local and remote log history to get rid of these revert logs. For example, when I want to keep the commits but remove log history for the last 4 revert commits, would it work to do git rebase -i HEAD~4 and selected fixup/squash for my local? If yes, would it work to then run git push -force so that the log history in remote syncs with my local and thus gets the last 4 log message cleaned?


Solution

    1. Reset last 4 commits git reset HEAD~4
    2. Saving your changes git stash
    3. Overwrite remote commit history git push --force-with-lease
    4. Apply stashed changes git stash pop
    5. Create a single commit git add --all & git commit

    Make sure your changes are not going to affect others!!!