我试过网上推荐的写法
git rm --cached git ls-files -i 
--exclude-from=.gitignore git
commit -m ‘Removed all files that are in the 
.gitignore‘
git push origin master 
--exclude-from=.gitignore顺便可以简写成
-X .gitignore,所以是这样:
git rm --cached git ls-files -i -X .gitignore
但没成功,有人这样写,我没测试,这是先删除再提交的做法:
git rm -r --cached .
git add .
git commit -m 
‘Removed all files that are in the .gitignore‘
git push origin master
如果用powershell:
($i in iex ‘git ls-files -i -X .gitignore‘) { git rm 
--cached $i } 
测试通过