Rewriting History

Changing the published commits is a bad practice as it will mess the history of other developers. Usually they will see both our old and new commits hence confused. Their old branches on top of the old commits will need to rebase on top of the new commits too.

However, rewriting history is the key to clean up our own branch that has not been published. We can amend commits, reword commits, squash commits and even get rid of one of them.

Tips: although you can get back your commits using reflog, creating a backup branch before rebasing can help you get back your original branch/commits in case anything wrong during rebase. Moreover, you can easily compare your rebased commits with the original ones. BTW, when creating the backup branch, you can untick the Checkout after create so as to stay on the original branch.

Last updated