Git sets the method to ignore the file. Gitignore

Time:2020-11-11

Create a new file named. Gitignore in the warehouse directory (because it starts with a dot, there is no file name, so you can’t create it directly in the windows directory. You must right-click git bash to create a new. Gitignore file in the Linux way). As shown in the figure below.

The. Gitignore file is valid for its directory and all subdirectories of its directory. By adding the. Gitignore file to the repository, other developers update the file to the local repository to share the same set of ignore rules.

The following ignore files are in the following format:

#Lines beginning with 'ා' are considered comments                          
#Ignore all filenames foo.txt File

foo.txt

#Ignore all generated HTML files,

*.html

Wei foo.html Manual maintenance is an exception

!foo.html

#Ignore all files and. O

*.[oa]

Configuration syntax:
A slash “/” is used to indicate the directory;
The asterisk “*” is used to match multiple characters;
Match a single character with the question mark “?”
A list of matches containing a single character in square brackets “[]”;
The exclamation mark “!” indicates that the matching file or directory is not ignored (tracked);

Common rules:
1) / MTK / filter entire folder
2) *. Zip filter all. Zip files
3) / MTK / do. C filter a specific file

The filtered files will not appear in Git repository (gitlab or GitHub). Of course, there are also files in the local library, but they will not be uploaded when they are pushed.
It should be noted that gitignore can also specify which files to add to version management:
1)!*.zip
2)!/mtk/one.txt

The only difference is that there is an exclamation mark at the beginning of the rule, and git will add files that meet the rules to version management.
Why are there two rules? Imagine a scenario where we only need to manage the one.txt Files, other files in this directory do not need to be managed, so we need to use:
1)/mtk/
2)!/mtk/one.txt
Assuming that we only have filter rules and do not add rules, then we need to remove the rules from the / MTK / directory one.txt Write all the documents except for it!

Finally, it should be emphasized that if you accidentally push the project before creating the. Gitignore file, even if you write new filtering rules in the. Gitignore file, these rules will not work, GIT will still version all the files.
Simply put, the reason for this is that Git is already managing these files, so you can’t filter them through filtering rules any more. Therefore, it is necessary to get into the habit of creating. Gitignore files at the beginning of a project, otherwise once pushed, it will be very troublesome to handle.

This article about the method of GIT setting ignore file. Gitignore will introduce this, more related git ignore file. Gitignore content, please search the previous articles of developpaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!