HGIGNORE(5)

πŸ’– hgignore(5) β€” the Mercurial Manual, bestie edition πŸ’–

okay so you opened hgignore(5) from the Mercurial Manual and you're about to have the cutest little epiphany about ignore files. welcome. this is the syntax for Mercurial ignore files, and yes it's giving "quietly powerful." πŸŽ€


✨ NAME ✨

hgignore β€” the syntax for Mercurial ignore files. that's it. that's the whole name. slay. πŸ’…


🌸 SYNOPSIS 🌸

Mercurial uses a file called .hgignore, and it lives in the root directory of a repository. it's the thing that controls Mercurial's behavior when it goes looking for files that it is not currently tracking. lowkey the bouncer at the club door. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so your working directory in a Mercurial repository is gonna be full of files that should not be tracked by Mercurial. we're talking backup files made by editors, build products made by compilers, all that chaos. 😭

you can ignore those files by listing them in a .hgignore file in the root of the working directory. and listen β€” the .hgignore file must be created manually. nobody's making it for you. it's typically put under version control, so the settings will propagate to other repositories with push and pull. icon behavior honestly. ✨

here's the actual rule, no cap: an untracked file is ignored if its path relative to the repository root directory, or any prefix path of that path, is matched against any pattern in .hgignore.

for example β€” say we have an untracked file, file.c, at a/b/file.c inside our repository. Mercurial will ignore file.c if any pattern in .hgignore matches a/b/file.c, a/b or a. see how it walks up the chain? main character energy. πŸ‘‘

plus! a Mercurial configuration file can reference a set of per-user or global ignore files. see the ignore configuration key on the [ui] section of hg help config for details of how to configure these files.

to control Mercurial's handling of files that it manages, lots of commands support the -I and -X options β€” see hg help <command> and hg help patterns for the details. 🧚

now the important bit, don't skip this: files that are already tracked are not affected by .hgignore, even if they appear in .hgignore. and an untracked file X can be explicitly added with hg add X, even if X would be excluded by a pattern in .hgignore. so you always have the final say. periodt. πŸ’œ


🌈 SYNTAX 🌈

an ignore file is a plain text file consisting of a list of patterns, with one pattern per line. empty lines are skipped. the # character is treated as a comment character, and the \ character is treated as an escape character.

Mercurial supports several pattern syntaxes. the default syntax used is Python/Perl-style regular expressions.

to change the syntax used, use a line of the following form:

syntax: NAME

where NAME is one of the following:

  • regexp β€” regular expression, Python/Perl syntax. 🐍
  • glob β€” shell-style glob. 🐚
  • rootglob β€” a variant of glob that is rooted (see below). 🌱

the chosen syntax stays in effect when parsing all patterns that follow, until another syntax is selected. so it's a vibe that carries forward until you say otherwise.

neither glob nor regexp patterns are rooted. a glob-syntax pattern of the form *.c will match a file ending in .c in any directory, and a regexp pattern of the form \.c$ will do the same. to root a regexp pattern, start it with ^. to get the same effect with glob-syntax, you have to use rootglob.

subdirectories can have their own .hgignore settings by adding subinclude:path/to/subdir/.hgignore to the root .hgignore. see hg help patterns for details on subinclude: and include:. πŸ“‚

Note β€” patterns specified in other than .hgignore are always rooted. please see hg help patterns for details.

πŸ“ EXAMPLE πŸ“

here is an example ignore file. look at her. she's perfect. πŸ’–

# use glob syntax.
syntax: glob

*.elc
*.pyc
*~

# switch to regexp syntax.
syntax: regexp
^\.pc/

πŸ’€ DEBUGGING πŸ’€

use the debugignore command to see if and why a file is ignored, or to see the combined ignore pattern. see hg help debugignore for details. genuinely such a useful little detective moment. πŸ”


πŸŽ€ AUTHOR πŸŽ€

Vadim Gelfer <vadim.gelfer@gmail.com>

Mercurial was written by Olivia Mackall <olivia@selenic.com>.


πŸ‘‘ SEE ALSO πŸ‘‘

hg(1), hgrc(5)


πŸ’… COPYING πŸ’…

this manual page is copyright 2006 Vadim Gelfer. Mercurial is copyright 2005-2026 Olivia Mackall. free use of this software is granted under the terms of the GNU General Public License version 2 or any later version.


🧚 AUTHOR 🧚

Vadim Gelfer <vadim.gelfer@gmail.com>

Organization: Mercurial


and that's the whole page bestie!! this was hgignore(5) from the Mercurial Manual β€” go forth and ignore files responsibly, ily, bye!! πŸ’–βœ¨πŸ¦‹πŸŒΈπŸŽ€