When using Git as a Code management tool, setting up Gitignore is an essential process, and some systems or ides generate files that are not related to the project in the directory that we do not expect to be submitted to the repository. It is important to understand the pattern rules of gitignore. I want to talk .
Pattern rules
For the Pattern rule, you can view git's related documentation: Http://git-scm.com/docs/gitignore, roughly the following: I want to talk .
- A blank line does not match anything, so it can be used as a block delimiter;
#
The beginning of the comment, if matched #
, can be preceded by a backslash, that is \#
;
- Unless a backslash is added, a string of spaces is ignored;
- If you precede the matched content
!
, the matched portions are moved out, and if you want to match the contents to the beginning, you need to add a backslash !
, such as \!important.txt
;
- If a match pattern is followed by a slash, such as
foo/
, the default matches the contents of the Foo folder in all (including parent-child folders), and it does not match a single file;
- If a match pattern does not contain a slash, for example
foo
, Git will match it as a shell lookup command.
Note **
: I need to talk .
- If a pattern
**
begins with, for example, the **/foo
Foo file (folder) in all folders is eventually matched;
- If a pattern
/**
begins with, for example abc/**
, all content in the ABC directory is matched;
- If a pattern is included
**
in the middle, such as a/**/b
, it will match, and a/b
a/x/b
a/x/y/b
all the similar content.
Gitignore related Problem Matching example
If we want to match the content of ' foo/bar/' in the ' foo ' directory, you can do this: I want to talk .
If you want to match the Node_modules folder in all directories, you only need to do this: I want to talk .
If you want to match all of the JSON files, you can do this: I want to talk .
git operation, add and then add Gitignore
Git operations often have this problem, when we git add
suddenly remembered to add a Gitignore file, but some such as node_modules/, cache/and other files have been added, these files will not be ignore off, how to do? I want to talk .
The most direct way is: I want to talk
# This step is equivalent to returning to git add previous step Git rm-r--cached. # and then add it again git add--all.
|
Git adds an empty folder
Git default is not to add empty folders, if you must join this folder, there are the following scenarios: I want to talk .
1) Add files in the folder and then delete the I want to speak
2) Add a .gitkeep
file to the folder I want to talk .
Let git not add gitignore files
If you add in the. gitignore file I want to speak
You will find that the. gitignore file is still being added to Git, why is there a need for it? Some people in the local development of some other folder name do not want to let others see, although in the Gitignore is ignored, but the. gitignore file can still see these folder names. I want to talk .
In fact, there is no good way to deal with this problem. Gitignore Multi-person collaborative development can be directly based on the same gitignore filter files, if you must do, you can remove from the add: I want to talk
Git operations involve a huge number of commands, but the daily development of the use of a few, the principle of clear, easy to use. I want to talk .
Reprint: http://www.barretlee.com/blog/2015/09/06/set-gitignore-after-add-file/
With the Gitignore.