使用新的gitignore文件重新同步git repo [英] Resync git repo with new gitignore file
问题描述
我只是在我的gitignore中添加了更多的ignorations(?),并且想要删除它东西已经在回购匹配新文件。
.gitignore文件不会忽略有点极端,但应该工作:
#rm所有文件
git rm -r --cached。
#按照新的.gitignore
添加所有文件git add。
#现在,提交新的.gitignore以应用
git commit -m.gitignore正在运行
(确保首先提交您想要保留的更改,以避免发生任何事故,如 jball037 评论如下。
- cached
选项可以让你的文件在你的磁盘上保持不变。)
在博客文章让Git忽略已经跟踪的文件 a>:
git rm --cached`git ls-files -i --exclude-standard`
Bassim 建议 $ b
路径中有空格的文件
如果遇到像
fatal:path spec'...'这样的错误信息与任何文件不匹配
,则可能是文件的路径中有空格。
您可以使用选项
- ignore-unmatch
删除所有其他文件:
git rm --cached --ignore-unmatch`git ls-files -i --exclude-standard`
但不匹配的文件将保留在您的存储库中,并且必须通过用双引号括住他们的路径:
git rm --cached< path.to .remaining.file>中
Is it possible to "refresh" a git repository after updating the gitignore file?
I just added more ignorations(?) to my gitignore and would like to remove stuff already in the repo matching the new file.
The solution mentioned in ".gitignore file not ignoring" is a bit extreme, but should work:
# 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"
(make sure to commit first your changes you want to keep, to avoid any incident as jball037 comments below.
The --cached
option will keep your files untouched on your disk though.)
You also have other more fine-grained solution in the blog post "Making Git ignore already-tracked files":
git rm --cached `git ls-files -i --exclude-standard`
Bassim suggests in his edit:
Files with space in their paths
In case you get an error message like
fatal: path spec '...' did not match any files
, there might be files with spaces in their path.You can remove all other files with option
--ignore-unmatch
:
git rm --cached --ignore-unmatch `git ls-files -i --exclude-standard`
but unmatched files will remain in your repository and will have to be removed explicitly by enclosing their path with double quotes:
git rm --cached "<path.to.remaining.file>"
这篇关于使用新的gitignore文件重新同步git repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!