.gitignore: Difference between revisions
Line 23: | Line 23: | ||
=Behavior in Presence of Currently Tracked Files= | =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|git rm --cached]]. | Files that are already tracked are not affected if a pattern that matches is specified in <code>.gitignore</code> after they Git started to track them. To stop tracking a file that is currently tracked, use <code>[[Git_rm#--cached|git rm --cached]]</code>. | ||
=Pattern Format= | =Pattern Format= |
Revision as of 06:57, 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
To download:
Use Cases
Negate an Exclusion Pattern Declared by Upper .gitignore Files
!