Git ignores the rules and the. Gitignore rule does not take effect for the workaround

Source: Internet
Author: User
Tags commit

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 '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.