Home > Development Tools > git > GIT ignores file '.gitignore' using

GIT ignores file '.gitignore' using

Guanhui
Release: 2020-07-24 17:26:19
forward
4816 people have browsed it

GIT ignores file '.gitignore' usingCreate a new file named .gitignore in the warehouse directory (because it starts with a dot and has no file name, it cannot be created directly in the windows directory. You must right-click Git Bash and create it according to the Linux method. .gitignore file). As shown below. The

.gitignore file is valid for the directory where it is located and all subdirectories of the directory where it is located. By adding a .gitignore file to a repository, other developers update that file to their local repository to share the same set of ignore rules.

The ignore files involved below are all in the following format:

# 以'#'开始的行,被视为注释.                          
# 忽略掉所有文件名是 foo.txt的文件.

foo.txt

# 忽略所有生成的 html文件,

*.html

# foo.html是手工维护的,所以例外.

!foo.html

# 忽略所有.o和 .a文件.

*.[oa]
Copy after login

Configuration syntax:
Start with a slash "/" to indicate the directory;
Use an asterisk "*" to wildcard Multiple characters;
Use a question mark "?" to wildcard a single character
Use square brackets "[]" to include a matching list of single characters;
Use an exclamation point "!" to indicate not ignoring (tracking) the matched File or directory;

Commonly used rules:
1)/mtk/ Filter the entire folder
2)*.zip Filter all .zip files
3)/mtk/do.c Filter a specific file

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

only The difference is that there is an exclamation mark at the beginning of the rule, and Git will add files that meet such rules to version management.
Why are there two rules? Imagine a scenario: If we only need to manage the one.txt file in the /mtk/ directory, and other files in this directory do not need to be managed, then we need to use:
1)/mtk/
2) !/mtk/one.txt
Assuming we only have filtering rules but no added rules, then we need to write out all the files in the /mtk/ directory except one.txt!

The final point that needs to be emphasized is that if you accidentally push the project before creating the .gitignore file, then even if you write new filtering rules in the .gitignore file, these rules will not take effect. , Git will still perform version management on all files.
Simply put, the reason for this problem is that Git has already started to manage these files, so you can no longer filter them through filtering rules. Therefore, you must develop the habit of creating a .gitignore file at the beginning of the project, otherwise it will be very troublesome to process once pushed.

Recommended tutorial: "Git Tutorial"

The above is the detailed content of GIT ignores file '.gitignore' using. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
git
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template