Home Explore Blog CI



git

3rd chunk of `Documentation/gitignore.adoc`
7631fb60da0b0f347ecd841e007576db5f4854fba4ed20e30000000100000f77
 is directly
   under directory "`foo`".

 - A trailing "`/**`" matches everything inside. For example,
   "`abc/**`" matches all files inside directory "`abc`", relative
   to the location of the `.gitignore` file, with infinite depth.

 - A slash followed by two consecutive asterisks then a slash
   matches zero or more directories. For example, "`a/**/b`"
   matches "`a/b`", "`a/x/b`", "`a/x/y/b`" and so on.

 - Other consecutive asterisks are considered regular asterisks and
   will match according to the previous rules.

CONFIGURATION
-------------

The optional configuration variable `core.excludesFile` indicates a path to a
file containing patterns of file names to exclude, similar to
`$GIT_DIR/info/exclude`.  Patterns in the exclude file are used in addition to
those in `$GIT_DIR/info/exclude`.

NOTES
-----

The purpose of gitignore files is to ensure that certain files
not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use
'git rm --cached' to remove the file from the index. The filename
can then be added to the `.gitignore` file to stop the file from
being reintroduced in later commits.

Git does not follow symbolic links when accessing a `.gitignore` file in
the working tree. This keeps behavior consistent when the file is
accessed from the index or a tree versus from the filesystem.

EXAMPLES
--------

 - The pattern `hello.*` matches any file or directory
   whose name begins with `hello.`. If one wants to restrict
   this only to the directory and not in its subdirectories,
   one can prepend the pattern with a slash, i.e. `/hello.*`;
   the pattern now matches `hello.txt`, `hello.c` but not
   `a/hello.java`.

 - The pattern `foo/` will match a directory `foo` and
   paths underneath it, but will not match a regular file
   or a symbolic link `foo` (this is consistent with the
   way how pathspec works in general in Git)

 - The pattern `doc/frotz` and `/doc/frotz` have the same effect
   in any `.gitignore` file. In other words, a leading slash
   is not relevant  if there is already a middle slash in
   the pattern.

 - The pattern `foo/*`, matches `foo/test.json`
   (a regular file), `foo/bar` (a directory), but it does not match
   `foo/bar/hello.c` (a regular file), as the asterisk in the
   pattern does not match `bar/hello.c` which has a slash in it.

--------------------------------------------------------------
    $ git status
    [...]
    # Untracked files:
    [...]
    #       Documentation/foo.html
    #       Documentation/gitignore.html
    #       file.o
    #       lib.a
    #       src/internal.o
    [...]
    $ cat .git/info/exclude
    # ignore objects and archives, anywhere in the tree.
    *.[oa]
    $ cat Documentation/.gitignore
    # ignore generated html files,
    *.html
    # except foo.html which is maintained by hand
    !foo.html
    $ git status
    [...]
    # Untracked files:
    [...]
    #       Documentation/foo.html
    [...]
--------------------------------------------------------------

Another example:

--------------------------------------------------------------
    $ cat .gitignore
    vmlinux*
    $ ls arch/foo/kernel/vm*
    arch/foo/kernel/vmlinux.lds.S
    $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
--------------------------------------------------------------

The second .gitignore prevents Git from ignoring
`arch/foo/kernel/vmlinux.lds.S`.

Example to exclude everything except a specific directory `foo/bar`
(note the `/*` - without the slash, the wildcard would also exclude
everything within `foo/bar`):

--------------------------------------------------------------
    $ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar
--------------------------------------------------------------

SEE ALSO
--------
linkgit:git-rm[1],
linkgit:gitrepository-layout[5],
linkgit:git-check-ignore[1]

GIT
---
Part of the linkgit:git[1] suite

Title: Advanced Git Ignore Patterns and Configuration
Summary
The text provides additional details on git ignore patterns, including special meanings of consecutive asterisks, configuration options, and examples of how to use .gitignore files to exclude files and directories, as well as how to stop tracking files and use git commands like 'git rm --cached' and 'git status'