.gitignore: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://git-scm.com/docs/gitignore#_pattern_format
=Internal=
=Internal=


* [[Git Configuration#Files|Git Configuration]]
* [[Git Configuration#Files|Git Configuration]]
* [[Git_Concepts#Ignoring_Files_for_Tracking|Ignoring Files for Tracking]]
=Overview=
<code>.gitingore</code> specifies files to exclude from tracking.
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
* Patterns read from a <code>.gitignore</code> file in the same directory as the path.
* 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 <code>$GIT_DIR/info/exclude</code>.
* 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 <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=
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=
==Ignoring Directories==
To ignore a directory, and recursively their content, specify then name of the directory (without any trailing slash). Example:
<syntaxhighlight lang='bash'>
.idea
</syntaxhighlight>
This wil ignore the <code>.idea</code> directory from the same directory as the <code>.gitignore</code> file, and recursively, the <code>.idea</code> directory content.


=Reference .gitignore=
=Reference .gitignore=


{{External|https://github.com/ovidiuf/templates/blob/master/reference-gitignore}}
{{External|https://github.com/ovidiuf/templates/blob/master/reference-gitignore}}
To download:
{{External|https://raw.githubusercontent.com/ovidiuf/templates/master/reference-gitignore}}
=Use Cases=
==Negate an Exclusion Pattern Declared by Upper .gitignore Files==
!
=Commands=
* [[Git check-ingore|git check-ignore]]
* [[Git add|git add]]

Latest revision as of 05:10, 11 January 2022

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

Ignoring Directories

To ignore a directory, and recursively their content, specify then name of the directory (without any trailing slash). Example:

.idea

This wil ignore the .idea directory from the same directory as the .gitignore file, and recursively, the .idea directory content.

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

!

Commands