How to remove a commit from the middle of a branch

You can use interactive (-i) rebase to remove a previous commit.

$ git log                          # copy the target commit 

$ git rebase -i <target-commit>~1  # start rebase from the previous commit of target commit

An editor will open with a list of commits, one per line. Each of these lines begins with pick. Comment out your target commit’s line (Put # at the start of target commit line).

OR, put drop or d instead of commenting out the line with #.

$ git rebase --continue      # repeat the command until finish rebase

Now, you need to do force (-f) push to remote since git history has been changed!

$ git push -f origin HEAD 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)