tags:

views:

42

answers:

2

Hi,

I'm using mercurial for a project. I want to ignore a file within the project folder so it cannot be added to source control accidentally. Looks like:

/myproject 
   /src
     private.cpp
     public.cpp

so I want to explicitly ban private.cpp from ever being added, is that possible?

Thanks

A: 

Sure it's possible. You need to add the path you wish to ignore as a filter in your .hgignore file for that repository. In the above, if your "myproject" folder is the repository, add the .hgignore there with this line in it:

*\src\private.cpp

For more information on how to use the .hgignore file look here.

Audie
Should I be able to see a .hgingore file in my project directory? I think someone else from this project has also added an ignore directive. I'm on mac os x but can't see any .hg files at all (though I am certain this folder is under mercurial control). Thanks.
if a .hgignore file is in use it will be visible in the root of your repository.
Toby Allen
Toby is correct. The .hgignore file must be located in the same directory as your .hg folder, which will be the root of your working directory. Unless your project directory is the root of your working directory, the .hgignore will not be in your project directory.
Audie
Files starting with a . are considered hidden on some operating systems. Try turning off hidden files.
Laurens Holst
Ok I see the file, can i just add my ignore file to it using a text editor, or is there some hg command I need to issue to add it to this file?
@user246114, you can edit the file directly. Make sure the editor you use doesn't try to change its name to .hgignore.txt or something else like that. The file name must be .hgignore and nothing else. If the file is under source control, make sure to let others in the project know what you are doing and why, or make sure your version doesn't get checked in. Good luck!
Audie
+2  A: 

You can use the hgignore file to specify files that are ignored for automatic operations (like hg addremove). This won't stop someone from explicitly adding the file via hg add src/private.cpp. You would have to use hooks to completely block commits containing that file though.

jamessan