Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of ignoring the file ".gitignore" in GIT

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the use example of ignoring the file ".gitignore" in GIT, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

Create a new file named.gitignore in the repository directory (because it starts with a dot, there is no file name, and it cannot be created directly in the windows directory. You must right-click Git Bash to create a new.gitignore file in the Linux way). This is shown below.

The.gitignore file is valid for the directory it is in and all subdirectories of the directory it is in. 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 starting with '#' are treated as comments. #Ignore all files named foo.txt #Ignore all generated html files,*.html# foo.html is manually maintained, so exceptions.! foo.html#Ignore all.o and.a files.*. [oa]

Configuration syntax:

Directories are indicated by slashes beginning with "/";

wildcard multiple characters with an asterisk "*";

With a question mark?" "Wildcard single character

Square brackets "[]" contain matching lists of single characters;

With an exclamation mark "! "indicates that matched files or directories are not ignored (tracked);

Common rules:

1)/mtk/Filter entire folder

2)*.zip Filter all.zip files

3)/mtk/do.c Filter a specific file

Filtered files will not appear in the git repository (gitlab or github), of course, there are local libraries, but push time will not upload.

Note that gitignore can also specify which files to add to version control:

1)!*. zip

2)!/ mtk/one.txt

The only difference is that the rules begin with an exclamation point, and Git adds files that satisfy these rules to version control.

Why are there two rules? Imagine a scenario: If we only need to manage one.txt file in the/mtk/directory, and none of the other files in this directory need to be managed, then we need to use:

1)/mtk/

2)!/ mtk/one.txt

Assuming we only have filtering rules and no rules added, we need to write all files in the/mtk/directory except one.txt!

One final point to emphasize is that if you accidentally push your project before creating the.gitignore file, even if you write new filtering rules in the.gitignore file, these rules will not work, and Git will still version all files.

The simple reason for this problem is that Git has started managing these files, so you can't filter them anymore. So make sure you get into the habit of creating.gitignore files at the beginning of your project, otherwise it can be a hassle to process once pushed.

Thank you for reading this article carefully. I hope Xiaobian will share the example of "ignoring files in GIT".gitignore". This article is helpful to everyone. At the same time, I hope everyone will support you more, pay attention to the industry information channel, and more relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 280

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report