Git – Remove commit from history

If it’s only on your local PC (or noone checked out your changes):

  1. Use: git log

to find the commit you want to remove. Copy hash (the long sqeuence like: e8348ebe553102018c…).

  1. Use: git rebase -i [hash]~ : for example git rebase -i e8348~

Just remove the commit you don’t need and save the file.

Interactive git rebase can let you also fix the broken commit – there is no need to remove it.

If you pushed changes to the server or someone already got your changes – never change history – it’d cause serious problems for your team.

Leave a Comment