.gitignore is invalid, some files cannot be filtered

In git, if you want to ignore a file and prevent the file from being submitted to the repository, you can use the method of modifying the .gitignore file in the root directory (if not, you need to manually create this file yourself). This file holds one matching rule per line such as:

 

 
# 此为注释 – 将被 Git 忽略
*.a       # 忽略所有 .a 结尾的文件
!lib.a    # 但 lib.a 除外
/TODO     # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

 

The rules are very simple and do not explain too much, but sometimes in the process of project development, I suddenly want to add some directories or files to the ignore rules on a whim. After the above method is defined, it is found that it does not take effect. The reason is that .gitignore can only ignore those For files that were not originally tracked, if some files have been included in version management, it is invalid to modify .gitignore. Then the solution is to delete the local cache first (change it to an untracked state), and then submit it:

 

?
 
git  rm  -r --cached .
git add .
git commit -m  'update .gitignore'

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326994653&siteId=291194637