git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 10, 2010, 19:56 UTC
Message-ID
<201009102156.31439.jnareb@gmail.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
Previous: Jakub NarebskiNext: Bruce Korb
Message 7 of 8 in “How do I .gitignore files starting with "#"?”
  1. Bruce KorbSep 10, 2010
  2. Jakub NarebskiSep 10, 2010
  3. Ævar Arnfjörð BjarmasonSep 10, 2010
  4. Bruce KorbSep 10, 2010
  5. Jakub NarebskiSep 10, 2010
  6. Jakub NarebskiSep 10, 2010
  7. Jakub NarebskiSep 10, 2010
  8. Bruce KorbSep 10, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.