如果不再需要某个文件(例如readme.txt),需要连同本地文件一起删除,则执行
git rm readme.txt
如果只是误提交了一些配置文件(例如 .settings 文件夹),本地文件不能删除,则执行(-r 表示递归删除)
git rm -r --cached .settings
之后就可以正常commit了。
------------------------------------------------
还有一种未测试的方法,可以比较方便的处理上面第一种情况
git 文档中 commit 有个 -a 参数:
- -a
- --all
-
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
所以,只要保证本地删除了文件,然后
git commit -am "xxxxx"
应该就可以了