| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 |
<meta name="generator" content="Docutils 0.21.2: https://docutils.sourceforge.io/" /> |
| 7 |
<meta name="author" content="Vadim Gelfer <vadim.gelfer@gmail.com>" /> |
| 8 |
<meta name="organization" content="Mercurial" /> |
| 9 |
<title>hgignore</title> |
| 10 |
<link rel="stylesheet" href="style.css" type="text/css" /> |
| 11 |
</head> |
| 12 |
<body> |
| 13 |
<div class="document" id="hgignore"> |
| 14 |
<span id="hgignore-5"></span> |
| 15 |
<h1 class="title">hgignore</h1> |
| 16 |
<h2 class="subtitle" id="syntax-for-mercurial-ignore-files">syntax for Mercurial ignore files</h2> |
| 17 |
<table class="docinfo" frame="void" rules="none"> |
| 18 |
<col class="docinfo-name" /> |
| 19 |
<col class="docinfo-content" /> |
| 20 |
<tbody valign="top"> |
| 21 |
<tr><th class="docinfo-name">Author:</th> |
| 22 |
<td>Vadim Gelfer <<a class="reference external" href="mailto:vadim.gelfer@gmail.com">vadim.gelfer@gmail.com</a>></td></tr> |
| 23 |
<tr><th class="docinfo-name">Organization:</th> |
| 24 |
<td>Mercurial</td></tr> |
| 25 |
<tr class="manual-section field"><th class="docinfo-name">Manual section:</th><td class="field-body">5</td> |
| 26 |
</tr> |
| 27 |
<tr class="manual-group field"><th class="docinfo-name">Manual group:</th><td class="field-body">Mercurial Manual</td> |
| 28 |
</tr> |
| 29 |
</tbody> |
| 30 |
</table> |
| 31 |
<div class="section" id="synopsis"> |
| 32 |
<span id="hgignore-5-gendoc"></span><h1>Synopsis</h1> |
| 33 |
<p>The Mercurial system uses a file called <tt class="docutils literal">.hgignore</tt> in the root |
| 34 |
directory of a repository to control its behavior when it searches |
| 35 |
for files that it is not currently tracking.</p> |
| 36 |
</div> |
| 37 |
<div class="section" id="description"> |
| 38 |
<h1>Description</h1> |
| 39 |
<p>The working directory of a Mercurial repository will often contain |
| 40 |
files that should not be tracked by Mercurial. These include backup |
| 41 |
files created by editors and build products created by compilers. |
| 42 |
These files can be ignored by listing them in a <tt class="docutils literal">.hgignore</tt> file in |
| 43 |
the root of the working directory. The <tt class="docutils literal">.hgignore</tt> file must be |
| 44 |
created manually. It is typically put under version control, so that |
| 45 |
the settings will propagate to other repositories with push and pull.</p> |
| 46 |
<p>An untracked file is ignored if its path relative to the repository |
| 47 |
root directory, or any prefix path of that path, is matched against |
| 48 |
any pattern in <tt class="docutils literal">.hgignore</tt>.</p> |
| 49 |
<p>For example, say we have an untracked file, <tt class="docutils literal">file.c</tt>, at |
| 50 |
<tt class="docutils literal">a/b/file.c</tt> inside our repository. Mercurial will ignore <tt class="docutils literal">file.c</tt> |
| 51 |
if any pattern in <tt class="docutils literal">.hgignore</tt> matches <tt class="docutils literal">a/b/file.c</tt>, <tt class="docutils literal">a/b</tt> or <tt class="docutils literal">a</tt>.</p> |
| 52 |
<p>In addition, a Mercurial configuration file can reference a set of |
| 53 |
per-user or global ignore files. See the <tt class="docutils literal">ignore</tt> configuration |
| 54 |
key on the <tt class="docutils literal">[ui]</tt> section of <a class="reference external" href="hgrc.5.html"><tt class="docutils literal">hg help config</tt></a> for details of how to |
| 55 |
configure these files.</p> |
| 56 |
<p>To control Mercurial's handling of files that it manages, many |
| 57 |
commands support the <tt class="docutils literal"><span class="pre">-I</span></tt> and <tt class="docutils literal"><span class="pre">-X</span></tt> options; see |
| 58 |
<a class="reference external" href="hg.1.html#<command>"><tt class="docutils literal">hg help <command></tt></a> and <a class="reference external" href="hg.1.html#patterns"><tt class="docutils literal">hg help patterns</tt></a> for details.</p> |
| 59 |
<p>Files that are already tracked are not affected by .hgignore, even |
| 60 |
if they appear in .hgignore. An untracked file X can be explicitly |
| 61 |
added with <a class="reference external" href="hg.1.html#add"><tt class="docutils literal">hg add X</tt></a>, even if X would be excluded by a pattern |
| 62 |
in .hgignore.</p> |
| 63 |
</div> |
| 64 |
<div class="section" id="syntax"> |
| 65 |
<h1>Syntax</h1> |
| 66 |
<p>An ignore file is a plain text file consisting of a list of patterns, |
| 67 |
with one pattern per line. Empty lines are skipped. The <tt class="docutils literal">#</tt> |
| 68 |
character is treated as a comment character, and the <tt class="docutils literal">\</tt> character |
| 69 |
is treated as an escape character.</p> |
| 70 |
<p>Mercurial supports several pattern syntaxes. The default syntax used |
| 71 |
is Python/Perl-style regular expressions.</p> |
| 72 |
<p>To change the syntax used, use a line of the following form:</p> |
| 73 |
<pre class="literal-block"> |
| 74 |
syntax: NAME |
| 75 |
</pre> |
| 76 |
<p>where <tt class="docutils literal">NAME</tt> is one of the following:</p> |
| 77 |
<dl class="docutils"> |
| 78 |
<dt><tt class="docutils literal">regexp</tt></dt> |
| 79 |
<dd>Regular expression, Python/Perl syntax.</dd> |
| 80 |
<dt><tt class="docutils literal">glob</tt></dt> |
| 81 |
<dd>Shell-style glob.</dd> |
| 82 |
<dt><tt class="docutils literal">rootglob</tt></dt> |
| 83 |
<dd>A variant of <tt class="docutils literal">glob</tt> that is rooted (see below).</dd> |
| 84 |
</dl> |
| 85 |
<p>The chosen syntax stays in effect when parsing all patterns that |
| 86 |
follow, until another syntax is selected.</p> |
| 87 |
<p>Neither <tt class="docutils literal">glob</tt> nor regexp patterns are rooted. A glob-syntax |
| 88 |
pattern of the form <tt class="docutils literal">*.c</tt> will match a file ending in <tt class="docutils literal">.c</tt> in any |
| 89 |
directory, and a regexp pattern of the form <tt class="docutils literal">\.c$</tt> will do the |
| 90 |
same. To root a regexp pattern, start it with <tt class="docutils literal">^</tt>. To get the same |
| 91 |
effect with glob-syntax, you have to use <tt class="docutils literal">rootglob</tt>.</p> |
| 92 |
<p>Subdirectories can have their own .hgignore settings by adding |
| 93 |
<tt class="docutils literal"><span class="pre">subinclude:path/to/subdir/.hgignore</span></tt> to the root <tt class="docutils literal">.hgignore</tt>. See |
| 94 |
<a class="reference external" href="hg.1.html#patterns"><tt class="docutils literal">hg help patterns</tt></a> for details on <tt class="docutils literal">subinclude:</tt> and <tt class="docutils literal">include:</tt>.</p> |
| 95 |
<div class="admonition note"> |
| 96 |
<p class="first admonition-title">Note</p> |
| 97 |
<p class="last">Patterns specified in other than <tt class="docutils literal">.hgignore</tt> are always rooted. |
| 98 |
Please see <a class="reference external" href="hg.1.html#patterns"><tt class="docutils literal">hg help patterns</tt></a> for details.</p> |
| 99 |
</div> |
| 100 |
</div> |
| 101 |
<div class="section" id="example"> |
| 102 |
<h1>Example</h1> |
| 103 |
<p>Here is an example ignore file.</p> |
| 104 |
<pre class="literal-block"> |
| 105 |
# use glob syntax. |
| 106 |
syntax: glob |
| 107 |
|
| 108 |
*.elc |
| 109 |
*.pyc |
| 110 |
*~ |
| 111 |
|
| 112 |
# switch to regexp syntax. |
| 113 |
syntax: regexp |
| 114 |
^\.pc/ |
| 115 |
</pre> |
| 116 |
</div> |
| 117 |
<div class="section" id="debugging"> |
| 118 |
<h1>Debugging</h1> |
| 119 |
<p>Use the <tt class="docutils literal">debugignore</tt> command to see if and why a file is ignored, or to |
| 120 |
see the combined ignore pattern. See <a class="reference external" href="hg.1.html#debugignore"><tt class="docutils literal">hg help debugignore</tt></a> for details.</p> |
| 121 |
</div> |
| 122 |
<div class="section" id="author"> |
| 123 |
<h1>Author</h1> |
| 124 |
<p>Vadim Gelfer <<a class="reference external" href="mailto:vadim.gelfer@gmail.com">vadim.gelfer@gmail.com</a>></p> |
| 125 |
<p>Mercurial was written by Olivia Mackall <<a class="reference external" href="mailto:olivia@selenic.com">olivia@selenic.com</a>>.</p> |
| 126 |
</div> |
| 127 |
<div class="section" id="see-also"> |
| 128 |
<h1>See Also</h1> |
| 129 |
<p><a class="reference external" href="hg.1.html"><strong>hg</strong>(1)</a>, <a class="reference external" href="hgrc.5.html"><strong>hgrc</strong>(5)</a></p> |
| 130 |
</div> |
| 131 |
<div class="section" id="copying"> |
| 132 |
<h1>Copying</h1> |
| 133 |
<p>This manual page is copyright 2006 Vadim Gelfer. |
| 134 |
Mercurial is copyright 2005-2026 Olivia Mackall. |
| 135 |
Free use of this software is granted under the terms of the GNU General |
| 136 |
Public License version 2 or any later version.</p> |
| 137 |
<span class="target" id="common"></span><!-- Common link and substitution definitions. --> |
| 138 |
</div> |
| 139 |
</div> |
| 140 |
</body> |
| 141 |
</html> |