用新的.gitignore文件重新同步git repo

克里斯蒂安·瓦滕加德

更新gitignore文件后是否可以“刷新” git存储库?

我刚刚在gitignore中添加了更多ignorations(?),并希望删除与新文件匹配的回购中已经存在的东西。

.gitignore文件不忽略”中提到的解决方案有点极端,但应该可以:

# rm all files
git rm -r --cached .
# add all files as per new .gitignore
git add .
# now, commit for new .gitignore to apply
git commit -m ".gitignore is now working"

(请确保首先提交您要保留的更改,以免发生以下jball037 注释引起的任何事件
--cached选项将使您的文件在磁盘上保持不变。)

在博客文章“使Git忽略已跟踪的文件”中,您还具有其他更细粒度的解决方案

git rm --cached `git ls-files -i --exclude-standard`

巴西姆在他的编辑中建议

路径中有空格的文件

如果您收到类似的错误消息fatal: path spec '...' did not match any files,则可能在文件路径中包含空格。

您可以使用option删除所有其他文件--ignore-unmatch

git rm --cached --ignore-unmatch `git ls-files -i --exclude-standard`

但是不匹配的文件将保留在您的存储库中,并且必须通过使用双引号将其路径括起来来显式删除它们:

git rm --cached "<path.to.remaining.file>"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章