Mercurial (hg) equivalent of git reset (–mixed or –soft)

The right way to replicate git reset --soft HEAD^ (undo the current commit but keep changes in the working copy) is:

hg strip --keep -r .

-1 will only work if the commit you want to strip is the very last commit that entered the repository. . refers to the currently checked out commit, which is the closest equivalent Mercurial has to Git’s HEAD.

Note that if . has descendants, those will get stripped away too. If you’d like to keep the commit around, then once you have the commit ID, you can instead:

hg update .^
hg revert --all -r <commit id>

This will update to the commit’s parent and then replace the files in the working copy with the versions at that commit.

Leave a Comment

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