How can I ignore everything under a folder in Mercurial
Asked Answered
M

6

155

I am looking for an expression for the .hgignore file, to ignore all files beneath a specified folder.

eg: I would like to ignore all files and folders beneath bin

Actually any advice on how the expressions are formed would be great

Melisent answered 31/10, 2008 at 15:55 Comment(0)
E
179

Alternately:

syntax: glob
bin/**
Excellent answered 31/10, 2008 at 22:5 Comment(8)
this is much easier I think :)Melisent
PhiLho, I think that would also filter out files named binShigella
This answer, plus this documentation helped me: selenic.com/mercurial/hgignore.5.htmlMofette
bin bin/ bin/* bin/** - All do the same thing with glob i.e. ignore all directories & sub-directories named bin but not any file name bin.txt or bin1 . What's the point of asterix?Cauda
I like it as clarity, but certainly use 'bin' if you've internalized the glob rules (I'm a re sort of guy)Excellent
I have had serious problems with ignoring bin, it seams to be special. I can have the correct pattern and it does not work, I then use another pattern (Debug the only subdirectory) and the directory is ignored, then switch back to the correct one and all is ok. I have no idea where this memory is coming from.Chrysoprase
I think that @buffer is wrong. For experience I have sow that when I use bin/ or bin/* only ignore one level and with bin/** it ignore things in bin and subfolders. But I think this is a bug or wrong interpretation of spec.Monzon
If you use TortoiseHg, here's a link about ignoring files that may be helpful. tortoisehg.readthedocs.io/en/latest/ignore.htmlBedder
M
55

I did some experiments and I found that the regex syntax on Windows applies to the path starting with the current repository, with backslashes transformed to slashes.

So if your repository is in E:\Dev for example, hg status will apply the patterns against foo/bar/file1.c and such. Anchors apply to this path.

So:

  • Glob applies to path elements and is rooted to element parts
  • foo matches any folder (or file) named foo (not to "foobar" nor "barfoo")
  • *foo* matches any folder or file with "foo" in the name
  • foo/bar* matches all files in "foo" folder starting with "bar"


  • Regex is case sensitive, not anchored
  • Of course, backslash regex special characters like . (dot)
  • / matches \ path separator on Windows. \ doesn't match this separator...
  • foo matches all files and folders with "foo" inside
  • foo/ matches only folders ending with "foo"
  • /foo/ matches the folder "foo" somewhere in the path
  • /foo/bar/ matches the folder "bar" in the folder "foo" somewhere in the path
  • ^foo matches file or folder starting by foo at the root of the repository
  • foo$ matches file ending with foo

I hope this will help, I found the HGIGNORE(5) page a bit succinct.

Mump answered 6/12, 2008 at 12:43 Comment(1)
I have the pattern ''[Dd]ebug*/'' in use and the strange Thing is, that it also filters files like ''debug.txt''Neelyneeoma
M
10

Both of those will also filter out a directory called cabin, which might not be what you want. If you're filtering top-level, you can use:

^/bin/

For bin directories below your root, you can omit the ^. There is no need to specify syntax, regexp is the default.

Monohydric answered 31/10, 2008 at 22:19 Comment(1)
This won't ignore anything. The caret says only things in the repo root but the leading slash catches only dirs not in the repo root.Excellent
D
3

syntax: glob bin/**

This answer is shown above, however I'd also like to add that * and ** are handled differently. ** is recursive, * is not.

See Hg Patterns

Dermis answered 14/11, 2016 at 22:8 Comment(0)
M
2

Nevermind, I got it

syntax: regexp
bin\\*

expressions follow standard perl regular expression syntax.

Melisent answered 31/10, 2008 at 16:9 Comment(1)
Indeed, and your expression means "file or folder ending with bin and followed by 0 or more backslashes"... So it works because the backslash is nullified by the *, but it applies anything with "bin" inside. On Windows, hg replaces \ by / before matching.Mump
C
-2

to ignore .class files

syntax: regexp
?\.class
Coastland answered 21/11, 2008 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.