项目开发中,有时候会把无需上传(test.txt)的文件commit,并push了,
这时在.gitignore文件里面添加"test.txt"已经不起作用了。
因为.gitignore只对从来没有commit过的文件起作用。这时有两种方法可以操作
一. 忽略文件夹
如果要删除目录下所有文件包括子目录中的
git rm -r --cached directory_name
二. 忽略文件
git rm --cached test.txt # 从版本库中rm 文件
## 在.gitignore中添加要忽略的文件
git commit -m 忽略文件
git push #推送到远程,从远程仓库中删除掉
其他成员pull,working directory中对应的文件会删除,所以如果文件重要,要提前备份
已经推送(push)过的文件,想在以后的提交时忽略此文件,即使本地已经修改过,而且不删除git远程库中相应文件
git update-index --assume-unchanged test.txt
如果需要恢复提交,使用
git update-index --no-assume-unchanged test.txt
git 改变文件的执行权限
git update-index --chmod=+x
# 或者
git update-index --chmod=-x