In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
For those of you who often use Git, the .gitignore configuration is no stranger. Don't talk too much nonsense, let's talk about the use of this .gitignore.
First of all, it is important to emphasize that the full file name of this file is ".gitignore". Notice that there is a "." at the beginning.
Generally speaking, every Git project needs a ".gitignore" file, which is used to tell Git which files do not need to be added to version management. In actual projects, many files do not require version management, such as .pyc files for Python and configuration files that contain passwords, and so on. The content of this file is some rules that Git will use to determine whether to add the file to version control.
Let's take a look at the common rules:
1) / mtk/ filter the entire folder
2) * .zip filters all .zip files
3) / mtk/do.c filter a specific file
Quite simply, filtered files will not appear in the git repository (gitlab or github). Of course, there are local libraries, but they will not be uploaded when push.
It is important to note that gitignore can also specify which files to add to versioning:
1)! * .zip
2)! / mtk/one.txt
The only difference is that there is an exclamation point at the beginning of the rule, and Git adds files that meet such rules to versioning.
Why are there two rules? Imagine a scenario: if we only need to manage the one.txt file in the / mtk/ directory, and no other files in this directory need to be managed, then we need to use:
1) / mtk/
2)! / mtk/one.txt
Assuming that we only have filtering rules without adding rules, then we need to write out all the files in the / mtk/ directory except one.txt!
Finally, it is important to emphasize 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 work, and Git will still version all files.
Simply put, the reason for this problem is that Git is already managing these files, so you can no longer filter them through filter rules. So be sure to get into the habit of creating .gitignore files at the beginning of the project, otherwise it will be very troublesome to deal with once push.
The .gitignore configuration file is used to configure files that do not need to be versioned. Configuring this file can bring great convenience to versioning. Here are some notes on configuring .gitignore:
1) configuration syntax:
Start with a slash "/" to indicate the directory
Match multiple characters with an asterisk "*"
With question mark "?" Wildcard single character
A matching list containing a single character in square brackets "[]"
With exclamation point "!" Indicates that matching files or directories are not ignored (tracked)
In addition, git matches the rules from the top to the bottom of the .rules profile, meaning that if the previous rules match more widely, the later rules will not take effect
2) sample illustration
A) rules: fd1/
Note: ignore all the contents under the directory fd1; note that both the / fd1/ directory under the root directory and a subdirectory / child/fd1/ directory will be ignored
B) rules: / fd1/
Description: ignore the entire contents of the / fd1/ directory under the root directory
C) rules:
/ *
! .gitignore
! / fw/bin/
! / fw/sf/
Description: ignore everything, but do not ignore the .gitignore file, / fw/bin/ and / fw/sf/ directories in the root directory
In fact, one thing that needs to be cleared is:
There are three ways to filter out files that you don't want to upload in Git, all of which can achieve your goal, but in different scenarios.
1) the first method
For the exclusion of files for a single project, this approach will allow all modifiers of the project to clone the filtering rules while cloning the code, without having to write another one, which ensures that all modifiers apply the same rule. Instead of Zhang San's own set of filtering rules, Li Si uses another set of filtering rules, which I prefer. The configuration steps are as follows:
Create a .gitignore file under the root of the project, and write the files or directories you want to exclude to the .gitignore file, in which there are two write methods.
A) use the command line to add exclusion files
Exclude files ending in .class echo "* .class" > .class (> > add at the end of the file, > delete existing content and then add), and then generate a .gitignore file in the current directory.
Exclude files in the bin directory echo "bin/" > .gitignore
B) the most convenient way is to open it with notepad, add the files or directories that need to be excluded, and add one per line, for example:
.class
.apk
Bin/
Gen/
.settings /
Proguard/
2) the second method
The global setting excludes files, which works globally. Any project managed by Git automatically excludes files or directories that are not under control when they are submitted. This method is more convenient for developers, as long as a global configuration, do not have to configure filtering rules every time the project is created. But this does not guarantee that after other developers clone your code, their rules are the same as yours, which leads to all kinds of conflicts in the code submission process.
The configuration steps are as follows:
A) like method (1), you need to create a .gitignore file and write in the file you want to exclude.
B) but here, we don't have to put the .gitnore file under a project, but anywhere, for example, we put it under the default Home path of Git, such as: / home/wangshibo/hqsb_ios
C) use the command to configure the global exclusion file gitconfig-- global core.excludesfile ~ / .gitignore, and you will find that excludesfile = / home/wangshibo/hqsb_ios/.gitignore appears in the ~ / .gitconfig file.
It shows that Git applies file filtering rules to the rules of Global.
3) the third method
Single project settings exclusion file, find .git / info/exclude in the project directory, and write in the file to be excluded:
.class
.apk
Bin/
Gen/
.settings /
Proguard/
This approach is discouraged, can only be configured for a single project, and cannot synchronize filtering rules to other developers, which has no advantage over method (1) (2).
-Git ignores rules and solutions to the ineffectiveness of .gitignore rules
In git, if you want to ignore a file and keep it from being submitted to the version library, you can use the method of modifying the .gitignore file in the root directory (if not, you need to create the file yourself). Each line of this file holds a matching rule such as:
This is a comment-will be ignored by Git
.a # ignore all files at the end of .a
! lib.a # except lib.a
/ TODO # only ignores the TODO file in the project root directory, not including subdir/TODO
Build/ # ignores all files in the build/ directory
Doc/.txt # ignores doc/notes.txt but does not include doc/server/arch.txt
The rules are very simple and do not explain too much, but sometimes in the project development process, suddenly want to add certain directories or files to the ignore rules, according to the above method definition found that did not take effect, because .gitignore can only ignore those files that were not originally track, if some files have been included in version management, then modify .gitignore is invalid. The solution is to delete the local cache (change it to a non-track state), and then submit:
Git rm-r-- cached.
Git add.
Git commit-m'update. Gitignore'
Note:
Don't get me wrong about the purpose of .gitignore files, which only work on Untracked Files, that is, files that have never been recorded by Git (files that have never been add and commit since they were added).
If files have been recorded by Git, then. Gitignore has no effect on them at all.
When you find that your talent can't support your ambition, please calm down and study.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.