tags:

views:

334

answers:

3

Suppose that I have made some changes in the working directory and accidentally marked several files (that include some of the modified ones) for removal. How do I unmark the files for removal without losing the changes I have made?

+2  A: 

hg revert

I'm pretty sure Mercurial even makes backups of your changes by default.

Pestilence
yes, unless you tell it not to, changes are put in .orig files
jk
A: 

there are two options using hg revert :

hg revert -a

which will go back to the previous revision and put all your changes in new files with .orig appended to the names

hg revert [names of files to unremove] to just revert those files

i'd probably go with the latter

jk
Ok I am aware of revert. Since I used "hg remove -Af" (i.e. remove the files from the repository in the next commit and not from the disk), I was looking for a solution that will just unmark the files so that that stay in the repository. "hg revert" will also replace them with previous versions. I expected there would be a way similar to "hg add"/"hg forget". "hg forget" just unmarks the files marked for addition in the next commit.
Kostas
AFAIK revert is your only option for un-removing - certainly the help for remove says to see revert for un-removing stuff (while as you say add suggests forget as an oposite). you should get .orig files with your changes in however
jk
A: 

Following your comment to jk, I checked hg forget. It seems to be just a shortcut for hg remove -Af, meaning that this is the real opposite of hg add.

Following that, if you've used hg remove -Af, then you should be able to revert that using hg add (I just tried it and seems to work).

Heim