Deleting commit from Mercurial via terminal

Let’s assume that you are already have repository.
I am going to create new branch for testing.

$ hg branch TestBranch
$ hg commit -m 'You can not delete this commit easly'

Now we need to configure (.hgrc or Mercurial.in) file for enabling strip extension. Add following lines to configuration file.

[extensions]
mq =

Before deleting last commit we need to get repository information for validating.

$ hg sum
parent: 344:9daa6f893e23 tip
made a new branch from revision 500
branch: newbranch
commit: (clean)
update: (current)
phases: 1 draft

Also we need changeset id for deleting commit. Our last commit changeset id 9daa6f893e23 and you can easly see on below. Or if you dont want to use hg sum and get directly changeset id, you can execute following command.

$ hg id -i
9daa6f893e23

$ hg strip 9daa6f893e23
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
saved backup bundle to C:\Codes\images\.hg\strip-backup/9daa6f893e23-e1200d21-backup.hg
$ hg sum
parent: 342:0ab421d404c2
Use the correct versions of ABC
branch: ABC
commit: (clean)
update: 1 new changesets, 2 branch heads (merge)

That’s all.