With the Gitignore.

Source: Internet
Author: User
Tags using git

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 .

    1. A blank line does not match anything, so it can be used as a block delimiter;
    2. #The beginning of the comment, if matched # , can be preceded by a backslash, that is \# ;
    3. Unless a backslash is added, a string of spaces is ignored;
    4. 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 ;
    5. 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;
    6. 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 .

foo/
!foo/bar/

If you want to match the Node_modules folder in all directories, you only need to do this: I want to talk .

node_modules/

If you want to match all of the JSON files, you can do this: I want to talk .

*. JSON
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

. gitignore

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

--cached. Gitignore

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.