Home > Article > Development Tools > How to set ignore in git
Git is a version control tool commonly used by programmers. When using Git for development, we may generate some temporary files or compilation result files, and these files do not need to be managed by Git. At this time, you need to use the ignore file to filter out these files to avoid including unnecessary files into version control.
In Git, the ignore file is a text file used to record files or folders filtered by Git. One file or folder per line, wildcards can be used for matching. When executing a Git command, Git will check the gitignore file and automatically filter out the files or folders. This can also prevent these files from being included in version control when submitting code.
The following describes how to use gitignore:
Git comes with a default global ignore file, which can be found in Use the following command in Git Bash to view:
$ git config --global core.excludesfile
You can see the path of the default ignore file.
We can use the following command to specify an ignore file in the global configuration.
$ git config --global core.excludesfile ~/.gitignore
Here we specify a file named .gitignore as the Git global ignore file.
In addition to using the global ignore file, we can also specify the ignore file separately for each project, just create .gitignore in the project Just file. We can create an ignore file in the project through the following command:
$ touch .gitignore
After the creation is completed, you can open the .gitignore file with an editor and add the files or folders that need to be filtered to the .gitignore file.
In the .gitignore file, use # to annotate the rules, one rule per line, and support the use of wildcards, including *,?, etc. The following are some common rules:
The following is a simple .gitignore file:
#忽略备份文件 *~ #忽略编译结果 /build #忽略特定的文件 .sass-cache/ #不忽略doc目录下的README.md文件 !doc/README.md
In the .gitignore file, if there is For the new ignore rules, you need to execute the following command to tell Git to update the ignore rules.
$ git rm -r --cached . $ git add . $ git commit -m 'update ignore rule'
The function of this command is:
Setting ignore files in Git is an important skill, which can help us avoid unnecessary files and code from being added to version control. I hope the above content can be helpful to everyone.
The above is the detailed content of How to set ignore in git. For more information, please follow other related articles on the PHP Chinese website!