git远端删除被提交后又被加到.gitignore的文件

远端删除文件而不影响本地文件

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
--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:
foreach($i in iex 'git ls-files -i -X .gitignore') { git rm --cached $i }
测试通过

参考: http://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore

posted @ 2014-02-14 12:02  $walker  阅读(448)  评论(0编辑  收藏  举报