The first method
.gitignore indicates the files under the ignored file directory. When git pushes, they will also appear in the pushed directory, or use git status to view the status. The files you want to ignore will still display the tracked status.
The reason is that in the GIT ignore directory, new files will be cached in GIT. If some files have been included in version management, even if the ignore path has been declared in .Gitignore, it will not work,
At this time, we should delete the local cache first, and then commit git, so that there will be no ignored files.
Solution: git clears the local cache (changes to untrack state), and then commits:
[[email protected] ~]# git rm -r --cached . [[email protected] ~]# git add . [[email protected] ~]# git commit -m 'update .gitignore' [[email protected] ~]# git push -u origin master
Special attention should be paid to:
1) .gitignore can only ignore files that have not been tracked. If some files have been included in version management, modifying. Gitignore is invalid.
2) If you want .Gitignore to work, you must make sure that these files are not in the staging area .Gitignore only ignores files that are not staged (cached),
For files that have been staged, the ignore file must be removed from the staged file before it can be ignored.
To remove a file from the staging area, use the command
use "git restore <file>..." to discard changes in working directory
Second method: (recommended)
Manually set in the warehouse under each clone. Do not check the changes of specific files.
[[email protected] ~]# git update-index --assume-unchanged PATH //Enter the files to be ignored in the PATH
- Solution to the invalidity of adding. Gitignore to the. Idea directory of IntelliJ idea
- [Solved] React project NPM run error: npm ERR! errno 1
- [Solution] fatal: ambiguous argument ‘[email protected]‘: unknown revision or path not in the working tree.
- git this exceeds GitHub’s file size limit of 100.00 MB
- [Solved] Please clean your repository working tree before checkout
- [Solved] Computer reboot causes broken git files
- [Solved] Pull is not possible because you have unmerged files
- Git LS files displays the current file status
- [Solved] Git conflict Error: commit your changes or stash them before you can merge
- [How to Solve Error] warning: LF will be replaced by CRLF in README.md.