Practical Git via GitExtensions
  • Git - a Distributed System
  • Bare Minimal Configurations
  • Creating a New Branch
  • Making a Commit
    • Adding only a portion of a file
    • Commit Message
    • Cherry-pick
    • Revert
  • Rewriting History
    • Rewording the Last Commit
    • Rewording Commit Message in Middle
    • Editing the Last Commit
    • Squashing Last Few Commits
    • Squashing Commits in Middle
    • Spliting Commit into Multiple
    • Removing a Commit
    • Pushing after Rewriting History
  • Lost and Found
  • Comparing Commits or Branches
  • Checking out a Branch into Another Folder
  • Blaming History
    • Blame
    • Bisect
  • Disabling Auto Tracking Branch
  • Line Ending
  • Ignore Unwanted Files
Powered by GitBook
On this page

Was this helpful?

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.

PreviousRevertNextRewording the Last Commit

Last updated 6 years ago

Was this helpful?