views:

4701

answers:

2

I want mercurial to remove several files from the current state of the repository. However, I want the files to exist in prior history.

How do forget and remove differ, and can they do what I want?

+5  A: 

From the documentation, you can apparently use either command to keep the file in the project history. Looks like you want remove, since it also deletes the file from the working directory.

From the Mercurial book at http://hgbook.red-bean.com/read/:

Removing a file does not affect its history. It is important to understand that removing a file has only two effects. It removes the current version of the file from the working directory. It stops Mercurial from tracking changes to the file, from the time of the next commit. Removing a file does not in any way alter the history of the file.

The man page hg(1) says this about forget:

Mark the specified files so they will no longer be tracked after the next commit. This only removes files from the current branch, not from the entire project history, and it does not delete them from the working directory.

And this about remove:

Schedule the indicated files for removal from the repository. This only removes files from the current branch, not from the entire project history.

Jason Catena
+31  A: 

'hg forget' is just shorthand for 'hg remove -Af'. From the 'hg remove' help:

...and -Af can be used to remove files from the next revision without deleting them from the working directory.

Bottom line: 'remove' deletes the file from your working copy on disk (unless you uses -Af) and 'forget' doesn't.

Ry4an
"hg forget" is re-introduced in Mercurial 1.3 as an easier way to do "hg remove -Af". It schedules the file for deletion without removing it from the working copy.
Martin Geisler
Glad to hear it. 'remove -Af' (and the whole table of options on the 'remove' help page) is/was craziness.
Ry4an
@Ry4an: Seriously, it was ridiculous. I contributed the patch that reintroduced 'forget'. When I was making it I realized that -Af made complete sense in the code but from a user's view it was completely ridiculous.
Steve Losh
Heh, that's what's so great about mercurial -- people are actively and iteratively thinking about what makes sense from a user's point of view. Thanks for fixing that one.
Ry4an
I thought I was the only one who considered this an essential feature
Mark Stahler
Can someone please give a real-world example of when you would use forget? I can't for the life of me come up with a situation in which I'd want to remove something from source control but keep it in my local directory.
mhenry1384
Local build configuration files or the like? Paths to local tools that differ from system to system? Accidentally added a log file that you don't want in source control, but want to save? I guess it happens.
Ry4an