.gitignore: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 14: Line 14:
Each line in the file specifies a [[#Pattern_Format|path pattern]], and when deciding to ignore or not a path, Git flattens the specifications from a set of files, while enforcing this precedence, listed here from highest to lowest:
Each line in the file specifies a [[#Pattern_Format|path pattern]], and when deciding to ignore or not a path, Git flattens the specifications from a set of files, while enforcing this precedence, listed here from highest to lowest:
* Pattern specified on command line
* Pattern specified on command line
* Patterns read from a .gitignore file in the same directory as the path.
* Patterns read from a <code>.gitignore</code> file in the same directory as the path.
* Patterns read from .gitignore files from parent directories. The patterns specified in .gitignore closer to the path in the hierarchy take precedence over those specified in more distant .gitignore files, along the directory hierarchy.
* Patterns read from <code>.gitignore</code> files from parent directories. The patterns specified in <code>.gitignore</code> closer to the path in the hierarchy take precedence over those specified in more distant <code>.gitignore</code> files, along the directory hierarchy.
* Patterns read from $GIT_DIR/info/exclude.
* Patterns read from <code>$GIT_DIR/info/exclude</code>.
* Patterns read from the file specified by the configuration variable core.excludeFiles.
* Patterns read from the file specified by the configuration variable <code>core.excludeFiles</code>.


Specify the files that all developers should ignore into .gitignore file(s) checked into the repository itself. Patterns that are specific to a particular repository but which do not need to be shared with other related repositories (auxiliary files that live inside the repository but are specific to one user's workflow) should go into $GIT_DIR/info/exclude. Patterns which a user wants Git to ignore in all situations (backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.
Specify the files that all developers should ignore into .gitignore file(s) checked into the repository itself. Patterns that are specific to a particular repository but which do not need to be shared with other related repositories (auxiliary files that live inside the repository but are specific to one user's workflow) should go into <code>$GIT_DIR/info/exclude</code>. Patterns which a user wants Git to ignore in all situations (backup or temporary files generated by the user’s editor of choice) generally go into a file specified by <code>core.excludesFile</code> in the user’s <code>~/.gitconfig</code>. Its default value is <code>$XDG_CONFIG_HOME/git/ignore</code>. If <code>$XDG_CONFIG_HOME</code> is either not set or empty, <code>$HOME/.config/git/ignore</code> is used instead.


=Behavior in Presence of Currently Tracked Files=
=Behavior in Presence of Currently Tracked Files=

Revision as of 06:52, 6 September 2021

External

Internal

Overview

.gitingore specifies files to exclude from tracking.

Each line in the file specifies a path pattern, and when deciding to ignore or not a path, Git flattens the specifications from a set of files, while enforcing this precedence, listed here from highest to lowest:

  • Pattern specified on command line
  • Patterns read from a .gitignore file in the same directory as the path.
  • Patterns read from .gitignore files from parent directories. The patterns specified in .gitignore closer to the path in the hierarchy take precedence over those specified in more distant .gitignore files, along the directory hierarchy.
  • Patterns read from $GIT_DIR/info/exclude.
  • Patterns read from the file specified by the configuration variable core.excludeFiles.

Specify the files that all developers should ignore into .gitignore file(s) checked into the repository itself. Patterns that are specific to a particular repository but which do not need to be shared with other related repositories (auxiliary files that live inside the repository but are specific to one user's workflow) should go into $GIT_DIR/info/exclude. Patterns which a user wants Git to ignore in all situations (backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

Behavior in Presence of Currently Tracked Files

Files that are already tracked are not affected if a pattern that matches is specified in .gitignore after they Git started to track them. To stop tracking a file that is currently tracked, use git rm --cached.

Pattern Format

Reference .gitignore

https://github.com/ovidiuf/templates/blob/master/reference-gitignore

To download:

https://raw.githubusercontent.com/ovidiuf/templates/master/reference-gitignore

Use Cases

Negate an Exclusion Pattern Declared by Upper .gitignore Files

!