Can you write comments in a .gitignore
file?
If so, should the line be preceded with a #
or some other indicator?
Yes, you may put comments in there. They however must start at the beginning of a line.
cf. http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files
The rules for the patterns you can put in the .gitignore file are as follows:
- Blank lines or lines starting with # are ignored.
[…]
The comment character is #
, example:
# no .a files
*.a
src/main/log/ # Doesn't work. git status still shows this directory
src/main/log/
Works fine. git status does not show the directory. In fact, it appears that any whitespace at the end of the line is considered part of the ignore pattern.
/
). If a file has a trailing space, the .gitignore
entry must match; 0 or 2 spaces and it fails. I consider it a bug. I'm using git version 1.7.5.4. It could be intentional, even if it probably shouldn't. But you can use [ ]
as a space character specifier. That is much better than allowing trailing white-space; it allows for the rare intentional trailing space, while making the more common (and hard to see) error case detectable.
Sep 9, 2012 at 20:57
git
was ignoring my .gitignore
. It was because I put end-of-line comments after some entries. The default VIM syntax coloring for config
filetypes misled me.
Dec 15, 2017 at 1:38
Do git help gitignore
.
You will get the help page with following line:
A line starting with # serves as a comment.
Also, I like using computers without command lines
- git is wrong place for you then, sorry.
git
is right place for everyone, just like rsync
. they just need good gui's, like dropbox. too sad we're still missing one for git...
git help ignore
(which is supported by git bash-completion)
Oct 21, 2019 at 16:43
git help help
.
Mar 21, 2020 at 5:57
#
will be formatted appropriately - easy to discover yourself that way!