Get the App
SLTechnology News&Howtos  ›  Servers  › 

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

Shulou Source: shulou.com Published: 2022-06-02 04:03:05 09月15日 Update

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!

Tags: File example directory configuration rule project build code time status processing help compilation method special pure one line warehouse function preface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Docker NVidia Redmi