How do I make mercurial ignore any file with .xxx extension

Jonathan picture Jonathan · May 20, 2011 · Viewed 15.9k times · Source

I want Mercurial to ignore any file with a certain extension.

For example, I wanted to ignore files with a .SUO extension. (There's no need to version-control Visual Studio user settings.)

So I changed my .hgignore file to this:

syntax: glob
*.suo

However, this has no effect, and Mercurial still sees my .suo file.

What am I doing wrong here?

Answer

Joel B Fant picture Joel B Fant · May 20, 2011

If, when running hg status before altering your .hgignore file, the .suo file had a ? in front of it, then it should be ignored now. If anything else (M or A for example) it is already tracked by the repository and will not magically stop being tracked. In such a case you'll need to do hg remove on the file to delete it and have hg stop tracking it, or just do hg forget on it to have hg stop tracking it but keep the file. Either should be followed by a commit.

The only files that will be omitted from the status listing if their path matches a pattern in the .hgignore file are files that are not tracked. It would make no sense to omit a file that is tracked, because you would never see whether it had been modified, added, or removed.

Edit: Mercurial does only track files (you can't make it track empty directories), but the patterns in .hgignore are simply run against strings of the file paths relative to the root of the repository. The very same relative paths that it shows you when you run hg status. So it does work how you say you want it to work because the following lines are a standard part of my own .hgignore files:

syntax: glob
*\obj\*
*\bin\*
*.csproj.user
*.suo

Again, when you run hg status and it shows a .suo file, what single character is at the beginning of that line? Is it a M, A, R, ! or ? character? What is the path after it?