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

16,302

Solution 1

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?

Solution 2

Mercurial uses entries in a file called .hgignore to determine what files it completely ignores. It is normally located in the root file for your repository (and not in the .hg directory, which you might think).

You can find out more here:

http://www.selenic.com/mercurial/hgignore.5.html

Normally, we use regular expression syntax to ensure that case is not a factor in extensions:

# use regexp syntax.
syntax: regexp
(?i)\.dcu
(?i)\.identcache
(?i)\.dof
(?i)\.dsk
(?i)\.bak
(?i)\.old

That way, it ensures that even if for some reason the case of the extension changes, it is still ignored.

Solution 3

Example for ignoring/excluding files with .o extension:

.*\.o$

should translate to .*\.suo$ for .suo extensions.
I have used this method successfully

Solution 4

Check where .hgignore file is located and ensure it is either in $HOME or project root folder. Check the CASE (vs case) of the extension. I doubt if pattern matching is case insensitive.

edit: tested, the pattern matching is NOT case sensitive. Hence, add "*.SUO" if you want to ignore files with ".SUO" extension.

Share:
16,302

Related videos on Youtube

Jonathan
Author by

Jonathan

Hello, I'm Jonathan! 👋 Experienced in Front End Development (HTML, CSS, ES6, Angular, React), Back End Development (C#, Java, NodeJS) and Software Engineering (OOP, RDBMS, TDD and beginning to branch into FP). Additionally trained and experienced in Interaction Design (User Research, Sketching, Wireframing, Prototyping, Accessibility). Focused on user needs, with an emphasis on relationships, empathy, evidence and results. I enjoy working in diverse, multi-disciplinary teams, learning and sharing knowledge. Made significant and lasting contributions to several high-impact projects in Australia, for: Bupa (2010), Westpac (2013), Service NSW (2015) and the Digital Transformation Agency (2017). Worked remotely for 5+ clients (including production support and across time-zones), with high self-motivation, productivity and communication (over email, IM and pull-requests). • Continuously programming since 2000 •

Updated on July 23, 2020

Comments

  • Jonathan
    Jonathan almost 4 years

    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?

    • John Zwinck
      John Zwinck about 13 years
      Are the files you are trying to ignore currently tracked (added) in your repo?
    • Joel B Fant
      Joel B Fant about 13 years
      By the way, this is on Windows, right?
  • Jonathan
    Jonathan about 13 years
    The file in question is all lower-case. I tried changing it to uppercase but it still doesn't work.
  • Jonathan
    Jonathan about 13 years
    Also the .hgignore is in the project root folder, and it works perfectly with: '/bin$ [linebreak] /obj$ [linebreak] wwwroot$'. It seems to only not work with file extension ignores.
  • Jonathan
    Jonathan about 13 years
    I tried the code above, and it still doesn't work. Even if I create a file called 'test.dcu', it still includes it in the list.
  • Jonathan
    Jonathan about 13 years
    But this isn't the behaviour I want. I want the ignored files to NOT be shown in the hg status list. This totally works fine for ignoring entire folders, such a debug, so why not .suo files? I guess the answer must have something to do with the fact that Mercurial notices only files, not folders?
  • Lasse V. Karlsen
    Lasse V. Karlsen about 13 years
    Note that you don't need to delete the file in question to make Mercurial stop tracking it, you just have to ask Mercurial to forget it. This will leave the file in place but stop the tracking. Remove (hg remove) is equivalent to hg forget and a file-system delete.
  • Nick Hodges
    Nick Hodges about 13 years
    Then your .hgignore file is being, well, ignored.
  • Nick Hodges
    Nick Hodges about 13 years
    Are you doing it from the command line? Maybe reset the command windows environment?