Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
git_ignore [2019/02/19 19:25] – [Basic .gitignore file] rpjdaygit_ignore [2019/02/22 18:18] (current) – [Debugging gitignore files] rpjday
Line 1: Line 1:
 ===== Overview ===== ===== Overview =====
  
-How to identify untracked files that Git should intentionally ignore when running numerous commands, such as ''git add -u'', ''git status'' and many more.+How to identify untracked files that Git should intentionally ignore when running numerous commands, such as ''git add -u'', ''git status'', ''git clean'' and many more.
  
 Some links: Some links:
Line 8: Line 8:
   * [[https://www.gitignore.io|Generate a gitignore file]]   * [[https://www.gitignore.io|Generate a gitignore file]]
  
-===== Basic .gitignore file =====+===== Introductory .gitignore ===== 
 + 
 +==== Basic .gitignore file ====
  
 Excerpts from the Linux kernel source top-level ''.gitignore'' file, which forces ignoring of all these file patterns //recursively//: Excerpts from the Linux kernel source top-level ''.gitignore'' file, which forces ignoring of all these file patterns //recursively//:
Line 58: Line 60:
 </code> </code>
  
-===== Four levels of ignoring files =====+==== Recursive .gitignore ==== 
 + 
 +Subdirectories can have more specific ''.gitignore'' files that take precedence in those subdirectories. For the Linux kernel source, the top-level directory ''scripts/'' has the ''.gitignore'' file: 
 + 
 +<code> 
 +
 +# Generated files 
 +
 +bin2c 
 +conmakehash 
 +kallsyms 
 +pnmtologo 
 +unifdef 
 +recordmcount 
 +sortextable 
 +asn1_compiler 
 +extract-cert 
 +sign-file 
 +insert-sys-cert 
 +</code> 
 + 
 +The Linux kernel source repo has over 200 ''.gitignore'' files. 
 +===== Advanced ignoring ===== 
 + 
 +==== Four levels of ignoring files ====
  
 Each line in a gitignore/exclude file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome): Each line in a gitignore/exclude file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):
Line 67: Line 93:
   * Patterns read from the file specified by the configuration variable ''core.excludesFile'' (possibly ''~/.my_ignorefile'').   * Patterns read from the file specified by the configuration variable ''core.excludesFile'' (possibly ''~/.my_ignorefile'').
  
-===== Rationale for different levels of gitignore files =====+==== Rationale for different levels of gitignore files ====
  
   * Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that //all// developers will want to ignore) should go into a ''.gitignore'' file that comes with the repository.   * Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that //all// developers will want to ignore) should go into a ''.gitignore'' file that comes with the repository.
Line 77: Line 103:
 </code> </code>
  
-===== Debugging gitignore files =====+==== Debugging gitignore files ====
  
 <code> <code>
 $ man git-check-ignore $ man git-check-ignore
 </code> </code>
 +
 +===== gitignore gotchas =====
 +
 +  * Since ''.gitignore'' is a versioned file, checking out a different commit might result in a different ''.gitignore'' file, causing unexpected behaviour.
  • git_ignore.1550604304.txt.gz
  • Last modified: 2019/02/19 19:25
  • by rpjday