Search code examples
mercurial

how do you revert 1 or more committed files in mercurial but NOT the entire changeset


Say I have files File_A, File_B and File_C. I edit File_A and File_B on purpose but File_C I just added some debugging code that I don't plan to commit. Then by accident I do a

hg commit -m "comment"

How do just revert/rollback/backout File_C? Basically I'd be happy to be able to go

hg update -r <oneRevBack> File_C
hg commit -m "put C back"

but update doesn't take a filter AFAIK so it's also going to revert File_A and File_B. I can copy File_C somewhere, hg update, then copy it back but that seems lame. Is there a way to do this directly in Mercurial?


Solution

  • The exact command you wanted to use would have worked if you used hg revert instead of hg update

    hg revert -r .^ File_C
    hg commit -m "put C back"