[英]How can I remove 'excluded' files from a Git repository?
What I'm doing: 我在做什么:
I'm working in Xcode, and started using Git not that long ago. 我在Xcode工作,很久以前就开始使用Git了。
As per normal, there are some files that I don't want to be included in the Git database, that are to do with Xcode settings. 按照惯例,有些文件我不想包含在Git数据库中,与Xcode设置有关。 I have already been using a Git repository for a while, but now want to remove these 'editor' files as they are creating problems.
我已经使用Git存储库了一段时间,但现在想要删除这些'编辑器'文件,因为它们会产生问题。
How I'm doing it: 我是怎么做的:
The proper way to do this is apparently not to use a .gitignore. 这样做的正确方法显然不是使用.gitignore。 Rather, it is to use .git/info/exclude.
相反,它是使用.git / info / exclude。 By creating a new project in Xcode and selecting the "use Git" option, I was able to find out that the default setting for this should be a .git/info/exclude file of the following:
通过在Xcode中创建一个新项目并选择“使用Git”选项,我能够发现这个的默认设置应该是以下的.git / info / exclude文件:
.DS_Store
.DS_Store
UserInterface.xcuserstate
UserInterface.xcuserstate
So I copied this exclude file over to the same git location for the project I'm working on, and it seems to be ok. 所以我将这个排除文件复制到我正在处理的项目的同一个git位置,似乎没问题。 Except...
除了...
What goes wrong: 出了什么问题:
The files of course will not be removed/untracked from my current project without manual intervention. 当然,如果没有人工干预,文件将不会从我当前的项目中删除/取消跟踪。 So, I've tried the following, which doesn't work and tells me there are no such files:
所以,我尝试了以下,这不起作用,并告诉我没有这样的文件:
git rm --cached .DS_Store
git rm --cached UserInterface.xcuserstate
But these files are definitely there, and if I go to commit my repo branch then all sorts of user interface files want to join the party too. 但是这些文件肯定存在,如果我去提交我的repo分支,那么各种用户界面文件也想加入聚会。
The Question: 问题:
So, what is the 'exclude' file actually doing? 那么,'排除'文件究竟在做什么? Is there a way to make the exclude file untrack or apply itself to all repo branches easily?
有没有办法让排除文件不被攻击或轻松地将自己应用于所有的回购分支?
If not, how can I get my project into the same state that it would be had I created the git repo from Xcode at square one? 如果没有,我怎样才能让我的项目进入与我在第一个方向从Xcode创建git repo时相同的状态?
One reason that the first git rm --cached
command you quoted would fail is that .DS_Store
is a directory. 你引用的第一个
git rm --cached
命令失败的一个原因是.DS_Store
是一个目录。 Try: 尝试:
git rm -r --cached .DS_Store
... instead. ......而是。 You might also want to check with
git ls-files
that there are actually files within that directory being tracked in the repository. 您可能还希望使用
git ls-files
检查存储库中是否跟踪了该目录中的实际文件。 If there weren't then that would also explain you getting an error. 如果没有,那也可以解释你得到一个错误。 Check that you're getting case of those files exactly right as well.
检查您是否也正确地获得了这些文件的大小写。
(These are generally useful exclude rules that I would add to .gitignore
, incidentally.) (这些通常很有用,不包括我偶然添加到
.gitignore
规则。)
To answer your other question: 回答你的另一个问题:
So, what is the 'exclude' file actually doing?
那么,'排除'文件究竟在做什么? Is there a way to make the exclude file untrack or apply itself to all repo branches easily?
有没有办法让排除文件不被攻击或轻松地将自己应用于所有的回购分支?
If files are already being tracked in the repository, you will still need to manually unstage them, regardless of whether they're being ignored / excluded. 如果已在存储库中跟踪文件,则仍需要手动取消它们,无论它们是否被忽略/排除。 Essentially, the various places you can add exclude rules all have the same syntax and semantics .
从本质上讲,您可以添加排除规则的各个地方都具有相同的语法和语义 。 The priority of those rules is also described in that documentation, but essentially:
这些规则的优先级也在该文档中描述,但基本上:
.gitignore
files, starting from the current directory and going up to the top level. .gitignore
文件,从当前目录开始,然后上升到顶层。 .git/info/exclude
is used. .git/info/exclude
。 core.excludesfile
. core.excludesfile
指定的文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.