Last Updated: February 25, 2016
·
318
· asenar

Git: rewrite your history

You can easily rewrite all your git history with git rebase --interactive (or git rebase -i ).

For example, typing git rebase -i HEAD^^^ will open your favorite text editor (vim) and will ask you what you want to do with the 3 last commits.

Some help text is at the bottom of the editor to explain you all what you can do :

  • remove a commit by removing the corresponding line,
  • reorder the commit history by changing the lines order,
  • reword the commit message,
  • edit the commit itself (adding the ; you forgotten, or insert one or more new commits),
  • meld 2 or more commit together with squash or fixup
  • you can also automatically execute some command with exec

If you do small commits, you will never have complex conflicts do deal with.

You can abort the rebase with git rebase --abort everytime git stop to let you do your modifications.