In Git, if you want to ignore a file and not commit the file to the repository, you can use the method that modifies the. gitignore file in the root directory (if none, you need to manually build the file yourself). Each row of this file holds a matching rule for example:
# This is a comment – will be ignored by Git
*.A # ignores all files ending with. A
!LIB.A # but except LIB.A
/todo # simply ignores the TODO file under the project root directory, excluding 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 simple, do not explain too much, but sometimes in the project development process, suddenly a sudden whim want to add some directories or files to ignore the rules, according to the above method definition found not effective, reason Yes. Gitignore can only ignore files that were not previously track, and if some files have already been included in version management, modify the. Gitignore is invalid. The workaround is to first delete the local cache (to change to a non-track state) before committing:
Git rm-r--cached.
git Add.
git commit-m ' update. Gitignore '
Turn from: Under the Sycamore Tree»git ignore rules and. Gitignore rule does not take effect solution
Git ignores the rules and the. Gitignore rule does not take effect for the workaround