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:
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:
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