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:
- Use the system default ignore file
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.
- Create project-specific ignore files
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.
- Write ignore rules
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:
- Ignore a file or folder: Just write the name of the file or folder.
- Ignore a certain type of file: Use the file suffix name as a rule, such as *.log to ignore all .log files.
- Ignore a folder and the files below it: You can use the folder name and wildcard characters to indicate.
- Exclusion rules: Use ! to indicate that a file or folder is not ignored.
The following is a simple .gitignore file:
#忽略备份文件 *~ #忽略编译结果 /build #忽略特定的文件 .sass-cache/ #不忽略doc目录下的README.md文件 !doc/README.md
- Usage of .gitignore file
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:
- Delete all information in the local Git repository
- Add the ignore rule back to the Git repository
- Submitting updated ignore rules
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!

GitHub is not difficult to learn. 1) Master the basic knowledge: GitHub is a Git-based version control system that helps track code changes and collaborative development. 2) Understand core functions: Version control records each submission, supporting local work and remote synchronization. 3) Learn how to use: from creating a repository to push commits, to using branches and pull requests. 4) Solve common problems: such as merge conflicts and forgetting to add files. 5) Optimization practice: Use meaningful submission messages, clean up branches, and manage tasks using the project board. Through practice and community communication, GitHub’s learning curve is not steep.

On your resume, you should choose to write Git or GitHub based on your position requirements and personal experience. 1. If the position requires Git skills, highlight Git. 2. If the position values community participation, show GitHub. 3. Make sure to describe the usage experience and project cases in detail and end with a complete sentence.

GitLab is better for some developers and teams because it provides a complete DevOps toolchain and powerful CI/CD capabilities. 1. GitLab's CI/CD function is integrated within the platform, supporting full process automation from code submission to deployment. 2. Its server-side rendering technology improves page loading speed for large projects. 3. GitLab's permission management system is more flexible and supports fine-grained control.

Microsoft does not own Git, but owns GitHub. 1.Git is a distributed version control system created by Linus Torvaz in 2005. 2. GitHub is an online code hosting platform based on Git. It was founded in 2008 and acquired by Microsoft in 2018.

Starting from Git is more suitable for a deep understanding of version control principles, and starting from GitHub is more suitable for focusing on collaboration and code hosting. 1.Git is a distributed version control system that helps manage code version history. 2. GitHub is an online platform based on Git, providing code hosting and collaboration capabilities.

The reason for using GitHub to manage HTML projects is that it provides a platform for version control, collaborative development and presentation of works. The specific steps include: 1. Create and initialize the Git repository, 2. Add and submit HTML files, 3. Push to GitHub, 4. Use GitHubPages to deploy web pages, 5. Use GitHubActions to automate building and deployment. In addition, GitHub also supports code review, Issue and PullRequest features to help optimize and collaborate on HTML projects.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
