git Git忽略本地删除的文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4589333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git ignore locally deleted folder
提问by Alexander Ljungberg
I have a Ruby on Rails application which crashes when vendor/rails
is present but works fine if it is not. I need to keep this folder deleted in my local copy so that I can work, but I don't want this deletion to ever be committed. Someone put it there for a reason.
我有一个 Ruby on Rails 应用程序,它在vendor/rails
存在时崩溃,但如果不存在则工作正常。我需要在我的本地副本中删除这个文件夹,以便我可以工作,但我不希望这个删除被提交。有人把它放在那里是有原因的。
So how do I delete this folder without it coming up in git status
as a thousand deleted files? Obviously .gitignore
won't work since you can't ignore files which are already tracked. Neither do any of the solutions listed here(git update-index --assume-unchanged
) work.
那么如何删除此文件夹而不将其git status
作为一千个已删除文件出现?显然是.gitignore
行不通的,因为您不能忽略已跟踪的文件。此处列出的任何解决方案( git update-index --assume-unchanged
) 都不起作用。
回答by Aristotle Pagaltzis
git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin
Note that because this is an index-based operation, you cannot set directories to be ignored – only individual files. If upstream ever adds a file inside those directories, you will have to repeat the fix-up.
请注意,因为这是一个基于索引的操作,所以您不能将目录设置为忽略——只能忽略单个文件。如果上游在这些目录中添加了一个文件,您将不得不重复修复。