Mercurial: how to undo last unpushed commit?

Based on information from this question:

hg strip --keep --rev .
--keep: do not modify working directory during strip
--rev . (the dot denotes the last commit. read sid0’s answer regarding descendants)


For people more familiar with git language, you are looking for git reset --mixed HEAD^

hard which would discard your changes, making your work “disappear” (I assume that is not an option)

soft would undo the commit, but keep previously committed files indexed (that is, tracked)

mixed keeps your changed files in place, but tells the index to undo the commit. in git-speak: git st would say Changes not staged for commit


See also git-reset docs , Difference git reset soft/mixed, git/hg Command equivalence table

Leave a Comment