Turn from: http://www.cnblogs.com/eddy-he/archive/2012/03/08/git_ignore_file.html
Software version:
Operating system: ubuntu10.04
Kernel versions: Linux version 2.6.32-36-generic
git versions: Git version 1.7.0.4
Directory:
1. Introduce
2. Global and Local
2.1 Global
2.2 Local
3. Grammar
4. Examples
5. Reference materials
1. Introduce
There are files that we don't want to join and don't need to be added to Git management, and we don't want him to appear in the not-yet-tracked list. For example, the O file generated during compilation. The ". Gitignore" file can achieve this effect.
2. Global and Local
Gitignore has global and local two kinds:
2.1 Global
Specify global ignore files by modifying the excludesfile in the global configuration git config. To set the method:
$git config--global core.excludesfile ~/.gitignore
Modify ~/.gitignore This file will be used for all GIT projects and for all tracked directories in the project instance. For example, we can add *.O to this file to ignore all. o files.
2.2 Local
Ignores the. Gitignore that the file defaults to the current directory, but it only works in the current directory. As mentioned above, adding *.O in the global. Gitignore file ignores the. o files that are generated in all directories, but adds *.O to the. Gitignore in the current directory, but only the. o files in the current directory.
3. Grammar
The syntax specification for Gitignore is as follows:
• All lines that start with a blank line or with an annotation symbol # will be ignored by Git;
• You can use a standard glob pattern match. * Match pattern last followed by backslash (/) description to ignore is the directory. * to ignore files or directories other than the specified mode, add an exclamation point (!) to the pattern before you reverse it.
Glob Pattern Matching:
• asterisk (*) matches 0 or more arbitrary characters;
· [ABC] matches any character that is listed in square brackets (this example either matches a A, matches a B, or matches a C);
• The question mark (?) matches only one arbitrary character;
· [0-9a-za-z] uses dashes in brackets to separate two characters, indicating that all of them can match (for example, [0-9a-za-z] matches all numbers 0 to 9 and all letters);
\ Escape character.
Note: In theory, it is permissible to add comments after the format file you want to ignore, but after my verification, it turns out that this does not achieve the desired result.
4. Examples
A. Gitignore example.
# This is an annotation-will be ignored by Git
# Ignore All. A files at the end of
# but except for LIB.A
!lib.a
/todo
# Ignore All files in the build/directory
build/
# ignores Doc/notes.txt but does not include Doc/server/arch.txt
Doc/*.txt
5. Reference materials
[1] "Pro git"