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

Explain in detail the solution that the .gitignore configured in git does not work.

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Explain in detail the solution that the .gitignore configured in git does not work.

Foreword:

Usually we want to keep the code in the warehouse clean, that is, do not include files generated by the project development tools, or temporary files after the project has been compiled. However, when we use git status to check the status of the workspace, we always prompt that some files have not been track. So we want git to help us ignore these files without reminding us.

Fortunately, git has taken this into account. We can create a .gitignore file under the root of the project, which is used to configure which files or directories are not track. The rule is simple: in this file, write down the files you don't want to be track, one line at a time. Blank lines and lines starting with # will be filtered out.

Here is a small example to illustrate the use of .gitignore files:

# A comment can be written here to indicate the purpose of this rule. The following example shows that the file is no longer track hello.class, because this is a compiled file, we can generate the file hello.class# as long as we have the source code, and we can also use wildcards. The following example shows that track is no longer used for all files ending in class * .class #! Indicates a special case, indicating that the previous rule should exclude the specified special file. # the following example shows that register.class does not apply the rule of * .class, and should be reminded that trackroomregister.class# can also deal with a directory. The following example shows that all files or directories in testDir can not be processed by tracktestDir/# or only files in a directory. For example, the following example shows that all files ending in doc in the testDir2 directory are not track, and other files will be reminded of track. Such as / testDir2/hello.txt/testDir2/*.doc

Normally, it will be fine after this configuration. But sometimes we find that an option in the configuration doesn't work. Why? Obviously there is no problem with the match, which makes people feel very puzzled.

The real reason is that .gitignore can only ignore files that have not been track, and if some files have been included in versioning, modifying .gitignore is invalid. A simple solution is to delete the local cache (change it to an untrack state) before committing.

Git rm-r-- cached .git add .git commit-m'update .gitignore'

If you have any questions, please leave a message or go to the community to exchange and discuss, thank you for reading, hope to help you, thank you for your support!

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

*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

Servers

Wechat

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

12
Report