views:

86

answers:

4

So I accidentally included a config file (different for each machine) into our mercurial repositories.

How can I get Mercurial to not include it in version control? I don't want to delete the file since I still want it. And I don't want to cause the file to get deleted on other developer's working directories either.

And how do I do this in TortoiseHG?

A: 

hg remove or hg remove -f? I think hg forget also removes it from the branch.

In both cases, files are retained in your directory.

rmk
'hg forget' is just short for 'hg remove -Af' (http://stackoverflow.com/questions/1101167/what-is-the-difference-between-hg-forget-and-hg-remove)
Nate
Also... hg remove without any options will delete the file from the local directory so that would not work in this case
Nate
A: 

add it to your ignore list.

See the .hgignore file.

TortoiseHG gives you access to this config file via the "Edit Ignore Filter" menu option.

rikh
+3  A: 

Right click on the file -> TortoiseHG -> Forget Files. Click Forget. Commit and Sync.

Edit: You'll also want to add the path to your .hgignore to keep it from getting added again. You can right click on the file in the HG Commit dialog and choose to ignore it.

Nate
Need to add the steps to add the config file to `.hgignore`, so it doesn't get reintroduced later on.
sdolan
+1, thanks. ___ <- because of the comment min limit.
sdolan
I tried this but when I did a push to the central repository, and then did an update on that machine, the file was deleted. This, do not want ...
Greg
Greg: Since you're ignoring the file now, you'll need to copy over the config file in the right location in each repo checkout.
sdolan
@sdolan: I was hoping to find a command that removes a file from the repository but doesn't delete the file.
Greg
@Greg: It will only delete it from the repository the first time you update after "forgetting" it. You can then copy it back in, and won't have to worry about it getting checked in/deleting again. There is no way that I know of to get around this on the scm level. What I do (and suggest doing) is adding a step to your deployment scripts (I use `fabric`) that does a soft link from the configuration file located in a separate conf directory on the server. This way if you do a new clone for whatever reason you'll always have the correct configuration in place. Hope that helps?
sdolan
+2  A: 

Here's the manual way of doing it through the command line:

  1. Copy the config file somewhere outside of the repository.
  2. Run hg rm path/to/config/file
  3. Add the config file path to your .hgignore.
  4. Commit the repository.
  5. Move the config file back to where you had it.
  6. Do an hg stat on your repository to double check you did everything right. (It shouldn't show up in the list of modified/added files).

Edit:

hg forget is the best way to do this.

  1. Run hg forget path/to/config/file
  2. Edit your .hgignore and add the path to the config file.
  3. hg ci to save your changes.
  4. Run hg stat to ensure everything worked according to plan.

See nates answer for how to do it TortoiseHG.

sdolan
-1? These steps will work just fine, just in 2 more commands than `forget`. `hg forget` does the equivalent of steps 1,2 and 5 in one shot. I didn't know it existed until right now, so I guess thanks for getting my attention, as it is a much more efficient way to do it.
sdolan
@Nate: He asked "How can I get Mercurial to not include it in version control?". That's what I answered. He included at the end "*And* how do I do this in TortoiseHG?".
sdolan
Looking at it again, you're right. The question does ask how to do it AND how to do it in Tortoisehg. If you make an edit (any edit), I'll remove my -1. Sorry about that.
Nate
No worries. I've also updated the answer to include the `hg forget` way of doing things.
sdolan
-1 changed to a +1. Good answer. Again, apologies for the quick trigger finger.
Nate
Cool, thanks! That little back and forth reminded me of http://xkcd.com/386/ :)
sdolan