Is there a difference between /dir and /dir/ in the .gitignore file within a Git repository?
How are the following different?
/
Git 2.23 (Q3 2019) attempts to revamp the description about slashes in gitignore patterns (used to indicate things like "anchored to this level only" and "only matches directories")
The documentation now includes:
The slash '
/' is used as the directory separator.
Separators may occur at the beginning, middle or end of the.gitignoresearch pattern.If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular
.gitignorefile itself.
Otherwise the pattern may also match at any level below the.gitignorelevel.If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.
For example, a pattern
doc/frotz/matchesdoc/frotzdirectory, but nota/doc/frotzdirectory;
howeverfrotz/matchesfrotzanda/frotzthat is a directory (all paths are relative from the.gitignorefile).An asterisk "
*" matches anything except a slash.
The character "?" matches any one character except "/".
The range notation, e.g.[a-zA-Z], can be used to match one of the characters in a range.
See fnmatch(3) and theFNM_PATHNAMEflag for a more detailed description.