本文翻译自:Applying .gitignore to committed files
I have committed loads of files that I now want to ignore. 我已经提交了许多文件,现在我想忽略它们。 How can I tell git to now ignore these files from future commits? 我怎样才能告诉git现在忽略以后的提交中的这些文件?
EDIT: I do want to remove them from the repository too. 编辑:我也想从存储库中删除它们。 They are files created after ever build or for user-specific tooling support. 它们是在构建后或为用户特定的工具支持后创建的文件。
#1楼
参考:https://stackoom.com/question/VaN4/将-gitignore应用于已提交的文件
#2楼
to leave the file in the repo but ignore future changes to it: 将文件保留在存储库中,但忽略以后的更改:
git update-index --assume-unchanged <file>
and to undo this: 并撤消此操作:
git update-index --no-assume-unchanged <file>
to find out which files have been set this way: 找出以这种方式设置了哪些文件:
git ls-files -v|grep '^h'
credit for the original answer to http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ 对于http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/的原始答案表示感谢
#3楼
Old question, but some of us are in git-posh
(powershell). 老问题了,但是我们当中有些人在git-posh
(powershell)中。 This is the solution for that: 这是解决方案:
git ls-files -ci --exclude-standard | foreach { git rm --cached $_ }
#4楼
Be sure that your actual repo is the lastest version 确保您的实际回购是最新版本
- Edit
.gitignore
as you wish 根据需要编辑.gitignore
-
git rm -r --cached .
-
git add .
then commit as usual 然后照常提交
#5楼
Follow these steps: 跟着这些步骤:
Add path to
gitignore
file 将路径添加到gitignore
文件Run this command 运行此命令
git rm -r --cached foldername
commit changes as usually. 像往常一样提交更改。
#6楼
- Edit
.gitignore
to match the file you want to ignore 编辑.gitignore
以匹配您要忽略的文件 -
git rm --cached /path/to/file
See also: 也可以看看: