将.gitignore应用于已提交的文件

本文翻译自: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 确保您的实际回购是最新版本

  1. Edit .gitignore as you wish 根据需要编辑.gitignore
  2. git rm -r --cached .
  3. git add .

then commit as usual 然后照常提交


#5楼

Follow these steps: 跟着这些步骤:

  1. Add path to gitignore file 将路径添加到gitignore文件

  2. Run this command 运行此命令

     git rm -r --cached foldername 
  3. commit changes as usually. 像往常一样提交更改。


#6楼

  1. Edit .gitignore to match the file you want to ignore 编辑.gitignore以匹配您要忽略的文件
  2. git rm --cached /path/to/file

See also: 也可以看看:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值