. Gitignore Detailed

Source: Internet
Author: User

This article turns from http://sentsin.com/web/666.html

Today is about one of the most important files in git ——. gitignore.

The first thing to emphasize is that the file's full filename is ". Gitignore", and note that there is a "." In the front. Files that do not have an extension are not well created under Windows, so here's how to create a win7:

Create a file with the file name: ". Gitignore.", notice that there is a point before and after. The system is automatically renamed to ". Gitignore" after saving.

In general, a ". Gitignore" file is required for each GIT project, and the purpose of this file is to tell git which files do not need to be added to version management.

In real-world projects, many files do not need to be versioned, such as Python. pyc files and some configuration files that contain passwords, and so on.

The contents of this file are rules that git will use to determine whether to add files to version control.

Let's look at the usual rules:

    • /mtk/Filtering the entire folder

    • *.zip filtering all. zip files

    • /MTK/DO.C filtering a specific file

Quite simply, the filtered files will not appear in your GitHub library, of course, the local library, but the push will not be uploaded.

It is important to note that Gitignore can also specify which files to add to version management:

    • !*.zip

    • !/mtk/one.txt

The only difference is that there is an exclamation point at the beginning of the rule, and git adds a file that satisfies that rule to version management.

Why should there be two kinds of rules? Imagine a scenario: we only need to manage the one.txt files in the/mtk/directory, and no other files in this directory need to be managed. Then we need to use:

    • /mtk/

    • !/mtk/one.txt

Assuming we only have filter rules without adding rules, we need to write out all the files except One.txt in the/mtk/directory!

The last thing to emphasize is that if you accidentally push the project before creating the. gitignore file, even if you write a new filter rule in the. gitignore file, the rules won't work, and git will still be versioning all the files.

Simply put, the problem is that git is already managing these files, so you can no longer filter them by filtering rules.

So make sure you get into the habit of creating. gitignore files at the start of a project, otherwise, once push is made, it can be cumbersome to handle.

(GO). Gitignore Detailed

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.