# How do I .gitignore files starting with "#"?

8 messages from 2010-09-10 to 2010-09-10. Participants: Bruce Korb, Jakub Narebski, Ævar Arnfjörð Bjarmason.
Thread: https://gitlist.dev/t/25069

## Bruce Korb, 2010-09-10 16:59

Subject: How do I .gitignore files starting with "#"?
Message-ID: <AANLkTimaPrDX4rn2xRYyLn-bh2rB-TgKaEtGSQ+JxSnM@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimaPrDX4rn2xRYyLn-bh2rB-TgKaEtGSQ%2BJxSnM%40mail.gmail.com

```
After trying lots of variations, I found it to be:

\#*

Not obvious and not easy to look up.  Please add it to your
.git/info/exclude sample text.  Thanks!

```

## Jakub Narebski, 2010-09-10 18:52

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <m38w39mnyd.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m38w39mnyd.fsf%40localhost.localdomain
In-Reply-To: <AANLkTimaPrDX4rn2xRYyLn-bh2rB-TgKaEtGSQ+JxSnM@mail.gmail.com>

```
Bruce Korb <bruce.korb@gmail.com> writes:

> After trying lots of variations, I found it to be:
> 
> \#*
> 
> Not obvious and not easy to look up.  Please add it to your
> .git/info/exclude sample text.  Thanks!

Well, it is quite obvious to me, as escaping special characters using
backslash is typical in Unix tools.  But you are right that this needs
to be documented.

Perhaps something like this?  I am not sure about example in
.git/info/exclude skeleton

-- >8 --
Subject: [PATCH] Document escaping of special characters in gitignore files

Requested-by: Bruce Korb <bruce.korb@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 Documentation/gitignore.txt |    6 ++++++
 templates/info--exclude     |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 7dc2e8b..67ae4d0 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -98,6 +98,12 @@ Patterns have the following format:
    For example, "/{asterisk}.c" matches "cat-file.c" but not
    "mozilla-sha1/sha1.c".
 
+ - You can escape special characters using backslash.
+   For example, "{backslash}#*" matches files beginning in `#`
+   (otherwise it would be considered comment),
+   and "{backslash}!*{backslash}?" matches files starting with `!`
+   (negate pattern prefix) and ending with `?` (glob wildcard).
+
 An example:
 
 --------------------------------------------------------------
diff --git a/templates/info--exclude b/templates/info--exclude
index a5196d1..2ebaf0d 100644
--- a/templates/info--exclude
+++ b/templates/info--exclude
@@ -4,3 +4,4 @@
 # exclude patterns (uncomment them if you want to use them):
 # *.[oa]
 # *~
+# \#*#
-- 
1.7.2.1

```

## Ævar Arnfjörð Bjarmason, 2010-09-10 18:59

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <AANLkTimw5pzdGjiPps-CE1PJS1sBXYw3dE4vhdwm1CYP@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimw5pzdGjiPps-CE1PJS1sBXYw3dE4vhdwm1CYP%40mail.gmail.com
In-Reply-To: <m38w39mnyd.fsf@localhost.localdomain>

```
On Fri, Sep 10, 2010 at 18:52, Jakub Narebski <jnareb@gmail.com> wrote:
> Bruce Korb <bruce.korb@gmail.com> writes:
>
>> After trying lots of variations, I found it to be:
>>
>> \#*
>>
>> Not obvious and not easy to look up.  Please add it to your
>> .git/info/exclude sample text.  Thanks!
>
> Well, it is quite obvious to me, as escaping special characters using
> backslash is typical in Unix tools.  But you are right that this needs
> to be documented.
>
> Perhaps something like this?  I am not sure about example in
> .git/info/exclude skeleton
>
> -- >8 --
> Subject: [PATCH] Document escaping of special characters in gitignore files
>
> Requested-by: Bruce Korb <bruce.korb@gmail.com>
> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
> ---
>  Documentation/gitignore.txt |    6 ++++++
>  templates/info--exclude     |    1 +
>  2 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
> index 7dc2e8b..67ae4d0 100644
> --- a/Documentation/gitignore.txt
> +++ b/Documentation/gitignore.txt
> @@ -98,6 +98,12 @@ Patterns have the following format:
>    For example, "/{asterisk}.c" matches "cat-file.c" but not
>    "mozilla-sha1/sha1.c".
>
> + - You can escape special characters using backslash.
> +   For example, "{backslash}#*" matches files beginning in `#`
> +   (otherwise it would be considered comment),
> +   and "{backslash}!*{backslash}?" matches files starting with `!`
> +   (negate pattern prefix) and ending with `?` (glob wildcard).
> +

Maybe fix this too in the same manpage:

    A line starting with # serves as a comment.

To:

    A line starting with # serves as a comment. Use \# for a literal #
character. See ...

```

## Bruce Korb, 2010-09-10 19:11

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <AANLkTi=D2M-QrbLodunphy+KJYt7eyfWsgzbwcBSZNyS@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DD2M-QrbLodunphy%2BKJYt7eyfWsgzbwcBSZNyS%40mail.gmail.com
In-Reply-To: <AANLkTimw5pzdGjiPps-CE1PJS1sBXYw3dE4vhdwm1CYP@mail.gmail.com>

```
On Fri, Sep 10, 2010 at 11:59 AM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Fri, Sep 10, 2010 at 18:52, Jakub Narebski <jnareb@gmail.com> wrote:
>> Bruce Korb <bruce.korb@gmail.com> writes:
>>
>>> After trying lots of variations, I found it to be:
>>>
>>> \#*
>>>
>>> Not obvious and not easy to look up.  Please add it to your
>>> .git/info/exclude sample text.  Thanks!
>>
>> Well, it is quite obvious to me, as escaping special characters using
>> backslash is typical in Unix tools.

Like cscope, for example?

  "#what ever"

Others use:

   ./#whatever

/etc/fstab requires \octal escapes, and not \xFF.

There are many unix standards to choose from, hence my suggestion. :)
That backslashes are sometimes used meant I found it before  pressing
"send".

```

## Jakub Narebski, 2010-09-10 19:33

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <201009102133.19427.jnareb@gmail.com>
URL: https://gitlist.dev/e/201009102133.19427.jnareb%40gmail.com
In-Reply-To: <AANLkTimw5pzdGjiPps-CE1PJS1sBXYw3dE4vhdwm1CYP@mail.gmail.com>

```
On Fri, 10 Sep 2010, Ævar Arnfjörð Bjarmason wrote:
> On Fri, Sep 10, 2010 at 18:52, Jakub Narebski <jnareb@gmail.com> wrote:
> > Bruce Korb <bruce.korb@gmail.com> writes:
> >
> > > After trying lots of variations, I found it to be:
> > >
> > > \#*
> > >
> > > Not obvious and not easy to look up.  Please add it to your
> > > .git/info/exclude sample text.  Thanks!
> >
> > Well, it is quite obvious to me, as escaping special characters using
> > backslash is typical in Unix tools.  But you are right that this needs
> > to be documented.
> >
> > Perhaps something like this?  I am not sure about example in
> > .git/info/exclude skeleton
> >
> > -- >8 --
> > Subject: [PATCH] Document escaping of special characters in gitignore files
> >
> > Requested-by: Bruce Korb <bruce.korb@gmail.com>
> > Signed-off-by: Jakub Narebski <jnareb@gmail.com>
> > ---
> >  Documentation/gitignore.txt |    6 ++++++
> >  templates/info--exclude     |    1 +
> >  2 files changed, 7 insertions(+), 0 deletions(-)
> >
> > diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
> > index 7dc2e8b..67ae4d0 100644
> > --- a/Documentation/gitignore.txt
> > +++ b/Documentation/gitignore.txt
> > @@ -98,6 +98,12 @@ Patterns have the following format:
> >    For example, "/{asterisk}.c" matches "cat-file.c" but not
> >    "mozilla-sha1/sha1.c".
> >
> > + - You can escape special characters using backslash.
> > +   For example, "{backslash}#*" matches files beginning in `#`
> > +   (otherwise it would be considered comment),
> > +   and "{backslash}!*{backslash}?" matches files starting with `!`
> > +   (negate pattern prefix) and ending with `?` (glob wildcard).
> > +
> 
> Maybe fix this too in the same manpage:
> 
>     A line starting with # serves as a comment.
> 
> To:
> 
>     A line starting with # serves as a comment. Use \# for a literal #
> character. See ...

Something like this?
-- >8 --
Subject: [PATCH] Document escaping of special characters in gitignore files

Requested-by: Bruce Korb <bruce.korb@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 Documentation/gitignore.txt |    6 ++++++
 templates/info--exclude     |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 7dc2e8b..67ae4d0 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -98,6 +98,12 @@ Patterns have the following format:
    For example, "/{asterisk}.c" matches "cat-file.c" but not
    "mozilla-sha1/sha1.c".
 
+ - You can escape special characters using backslash.
+   For example, "{backslash}#*" matches files beginning in `#`
+   (otherwise it would be considered comment),
+   and "{backslash}!*{backslash}?" matches files starting with `!`
+   (negate pattern prefix) and ending with `?` (glob wildcard).
+
 An example:
 
 --------------------------------------------------------------
diff --git a/templates/info--exclude b/templates/info--exclude
index a5196d1..2ebaf0d 100644
--- a/templates/info--exclude
+++ b/templates/info--exclude
@@ -4,3 +4,4 @@
 # exclude patterns (uncomment them if you want to use them):
 # *.[oa]
 # *~
+# \#*#
-- 
1.7.2.1

```

## Jakub Narebski, 2010-09-10 19:41

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <201009102141.30416.jnareb@gmail.com>
URL: https://gitlist.dev/e/201009102141.30416.jnareb%40gmail.com
In-Reply-To: <AANLkTi=D2M-QrbLodunphy+KJYt7eyfWsgzbwcBSZNyS@mail.gmail.com>

```
Bruce Korb wrote:
> On Fri, Sep 10, 2010 at 11:59 AM, Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> On Fri, Sep 10, 2010 at 18:52, Jakub Narebski <jnareb@gmail.com> wrote:
>>> Bruce Korb <bruce.korb@gmail.com> writes:
>>>
>>>> After trying lots of variations, I found it to be:
>>>>
>>>> \#*
>>>>
>>>> Not obvious and not easy to look up.  Please add it to your
>>>> .git/info/exclude sample text.  Thanks!
>>>
>>> Well, it is quite obvious to me, as escaping special characters using
>>> backslash is typical in Unix tools.
> 
> Like cscope, for example?
> 
>   "#what ever"
> 
> Others use:
> 
>    ./#whatever

Actually "/#whatever" would also work, but it would have different meaning,
anchoring filename so only files in given directory matches.

> 
> /etc/fstab requires \octal escapes, and not \xFF.

They are not escapes, but quoting of metacharacters (special characters).

> 
> There are many unix standards to choose from, hence my suggestion. :)
> That backslashes are sometimes used meant I found it before  pressing
> "send".

:-)

-- 
Jakub Narebski
Poland

```

## Jakub Narebski, 2010-09-10 19:56

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <201009102156.31439.jnareb@gmail.com>
URL: https://gitlist.dev/e/201009102156.31439.jnareb%40gmail.com
In-Reply-To: <201009102133.19427.jnareb@gmail.com>

```
Jakub Narebski wrote:

> Something like this?

Err, rather like this.
-- >8 --
Subject: [PATCH] Document escaping of special characters in gitignore files

Requested-by: Bruce Korb <bruce.korb@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 Documentation/gitignore.txt |    7 +++++++
 templates/info--exclude     |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 7dc2e8b..20abc20 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -68,6 +68,7 @@ Patterns have the following format:
    for readability.
 
  - A line starting with # serves as a comment.
+   Use `\#` for a literal # character starting filename.
 
  - An optional prefix '!' which negates the pattern; any
    matching file excluded by a previous pattern will become
@@ -98,6 +99,12 @@ Patterns have the following format:
    For example, "/{asterisk}.c" matches "cat-file.c" but not
    "mozilla-sha1/sha1.c".
 
+ - You can escape special characters using backslash.
+   For example, "{backslash}#*" matches files beginning in `#`
+   (otherwise it would be considered comment),
+   and "{backslash}!*{backslash}?" matches files starting with `!`
+   (negate pattern prefix) and ending with `?` (glob wildcard).
+
 An example:
 
 --------------------------------------------------------------
diff --git a/templates/info--exclude b/templates/info--exclude
index a5196d1..2ebaf0d 100644
--- a/templates/info--exclude
+++ b/templates/info--exclude
@@ -4,3 +4,4 @@
 # exclude patterns (uncomment them if you want to use them):
 # *.[oa]
 # *~
+# \#*#
-- 
1.7.2.1

```

## Bruce Korb, 2010-09-10 20:52

Subject: Re: How do I .gitignore files starting with "#"?
Message-ID: <AANLkTim4+_GWdnzEGsiqwbySN7uy+7MgwnCYXWiVgjqQ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim4%2B_GWdnzEGsiqwbySN7uy%2B7MgwnCYXWiVgjqQ%40mail.gmail.com
In-Reply-To: <201009102156.31439.jnareb@gmail.com>

```
On Fri, Sep 10, 2010 at 12:56 PM, Jakub Narebski <jnareb@gmail.com> wrote:
> Jakub Narebski wrote:
>
>> Something like this?

> diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
> index 7dc2e8b..20abc20 100644
> --- a/Documentation/gitignore.txt

I think the prototype for info/exclude is a good idea, too.

>> /etc/fstab requires \octal escapes, and not \xFF.
>
> They are not escapes, but quoting of metacharacters (special characters).

./#
\#
"#"
\043
\x23
&35;

whatever you care to call it, however you spell it, the result is intended to be
the same:  This sequence of characters is to be interpreted as part of the token
and not special annotation (or token separator) characters.

Anyway, thanks for fixing the doc.  - Bruce

```
