Transfer from http://www.pfeng.org/archives/840
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. A end-of-file
!lib.a # but LIB.A except
/todo # simply ignores the TODO file under the project root, not including subdir/ TODO
build/ # ignores all files under 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, The reason is that. 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 not valid. 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 '