#git rebase

Delete a commit from branch in Git

I sure that there is at least once time in the life of a programmer, they need to delete a commit in the history of a branch. So I write this post to share you the way to delete a commit from branch in Git.

My example is we have a git log tree as below:

And you are working on branh DEV, you need to remote “Commit C” from branch DEV. So you should use command git rebase -i

In there, “ea61baa” is the hash key of “Commit C”. After entering the command, a editor will be opened with the content below:

You have to remove line

After that, save it.

You are done, just re-check by git log command

You can see that “Commit C” now is not in branch dev.