参考:https://www.jianshu.com/p/a09a9b40ad20
之前在使用git 的过程中,遇到忽略文件一直不生效的问题
如何确认规则是否生效
git check-ignore -v file
ex:
.flutter-plugins-dependencies
如果规则生效,则会返回
main_bundle/.gitignore:43:.flutter-plugins-dependencies .flutter-plugins-dependencies
即告诉你对应的哪条规则是生效的,但是有的时候明显觉得添加规则是没有问题的,可文件件就是忽略不了。那就是因为你的文件已经在跟踪的工作列表时,比如以下示例中的".flutter-plugins-dependencies"文件
input :
git status
output:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .flutter-plugins-dependencies
所以就需要将文件移出工作区,它才会生效:
git rm .flutter-plugins-dependencies --cached
这个时候查看文件就可以看到,文件在git中已经标记为deleted了,也就不会被工程跟踪了。
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .flutter-plugins-dependencies
modified: .gitignore
另外再补充一点,如何需要在跟踪此文件需要使用:
git add -f .flutter-plugins-dependencies
加“-f”的原因是因为文件已经默认被忽略了。