问题
I have the following in my .hgignore
file:
syntax: glob
obj/*
bin/*
*.suo
*.user
*.ncb
If I comment out the *.
filters, the filtering works fine filtering out the files in the bin
and obj
folder, however, if I keep those filters in I receive the following error:
abort: c:\temp\.hgignore: invalid pattern (relre): *.suo
Note: The file is encoded in UTF-8
回答1:
The error message from Mercurial tells us that your syntax: glob
line is not read by Mercurial. Patterns in ignore files default to regular expressions, and *.suo
is indeed an invalid regular expression (a regex cannot start with *
).
Since this is on Windows, and since the file is UTF-8 encoded, then the only reasonable explanation is that there is somehthing that makes Mercurial ignore the syntax: glob
line. An UTF-8 BOM is such a "something"! A byte order mark is a small signature inserted into UTF-16 encoded files to signal the byte order of the file. This is not needed or recommended for UTF-8 encoded files, but Windows editors have a tendency to insert them anyway.
To fix this, please open the file in Notepad and choose "Save As". Then pick ANSI as the encoding. Your .hgignore
file is pure ASCII, so this will effective be the same as UTF-8 without a BOM.
回答2:
To ignore the complete bin
and obj
folders, you don't need the /*
behind them.
My default .hgignore
file for Visual Studio projects looks like this:
syntax: glob
bin
obj
*.suo
*.user
回答3:
mercurial is somehow not interpreting the line syntax: glob because of the BOM (Byte-Order-Mark inserted right in front of the file, on windows x86-x64 running on Intel platform uses little endian) on windows platform you have to save the file as ASCII as contactmatt has advised.
Interestingly you can see the 2 byte BOM (Byte-Order-Mark) in hex view of the file saved on windows platform using utf-8 encoding
Now try to save this file using notepad in ASCII encoding and you would see that Byte-Order-Mark would be removed and mercurial would stop complaining about it. Attaching hex view after saving the file in ASCII.
来源:https://stackoverflow.com/questions/8798678/mercurial-gives-invalid-pattern-error-for-simple-glob-syntax