Remove file from a commit in Mercurial

Try out:

hg forget somefile.txt
hg commit --amend

If the file was new (i.e. you had used hg add).

If that file already existed try:

cp somefile.txt somefile.txt.bak
hg revert somefile.txt --rev .~1
hg commit --amend

Which is basically telling mercurial to revert the file (somefile.txt) back to the state it was one revision ago (--rev .~1).

Just make sure to back up the file you are reverting before entering the command so that you do not lose your changes. I was under the impression mercurial does this automatically for you, but after testing it quickly I’m not so sure.

Leave a Comment

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