gitfilesystems

Where is the Git dot (.) current directory pathspec documented?


From both my past experience and current Internet research, the . in Git commands such as git add . appears to be a pathspec which matches the current directory. However, I'm not seeing this defined in the official git documentation at git-scm.com.

The pathspec documentation says:

The pathspec syntax is as follows:

  • any path matches itself
  • the pathspec up to the last slash represents a directory prefix. The scope of that pathspec is limited to that subtree.
  • the rest of the pathspec is a pattern for the remainder of the pathname. Paths relative to the directory prefix will be matched against that pattern using fnmatch(3); in particular, * and ? can match directory separators.

Following these rules tells me that . is probably matched by fnmatch(3). According to man7.org, fnmatch(3) checks whether the string argument matches the pattern argument, per glob(7):

The fnmatch() function checks whether the string argument matches the pattern argument, which is a shell wildcard pattern (see glob(7)).

The glob(7) documentation defines a number of special wildcard characters, but does not seem to have any special support for ..

A string is a wildcard pattern if it contains one of the characters '?', '*', or '['.

What am I missing here? Why does . match all files in the current directory, and where is this documented?


Solution

  • . is a file system entry in Unix-like operating systems and Windows (plus various other operating systems) which refers to the current working directory.

    Since . is a path to the current working directory according to the file system, the first pathspec syntax rule ("any path matches itself") causes it to have the exact same meaning in Git.