远端删除文件而不影响本地文件
git rm [-r] --cached file_or_dir_name
利用.gitignore来自动删除所有匹配文件
我试过网上推荐的写法
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
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:
git add .
git commit -m 'Removed all files that are in the .gitignore'
git push origin master
foreach($i in iex 'git ls-files -i -X .gitignore') { git rm --cached $i }
测试通过