从git中删除.xcuserstate和DS_Store文件 [英] Removing .xcuserstate and DS_Store files from git

查看:195
本文介绍了从git中删除.xcuserstate和DS_Store文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode中,我注意到.DS_Store和* .xcuserstate总是改变,不需要提交。所以,我写了一个.gitignore文件,其中包含:

  .DS_Store 
* .xcuserstate

以及其他条目。然后我使用:

pre $ git rm --cached * xcuserstate
git rm - cached .DS_Store

删除版本控制下的这些文件类型。但是,当我去合并时,Xcode告诉我有需要提交的更改。这些更改包括.DS_Store文件和.xcuserstate文件。



所以,我试过这个:

  find。 -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch 
找到。 -name * .xcuserstate -print0 | xargs -0 git rm --ignore-unmatch

我得到了同样的结果。如何从源代码管理中删除这些文件?

您需要在将它们从暂存区域中删除后进行修改。



正如您所做的那样,运行:

  $ git rm --cached path / to / .DS_Store 
$ git rm --cached * .xcuserstate

请注意,您可能在其他目录中有一些目录,因此您可能需要多次调用才能完成所有目录。此时,您的删除会在索引中进行,但还有很多事情要做:添加您的 .gitignore ,并提交最终结果:

  $ git add .gitignore 
$ git commit -m删除并忽略.xcuserstate和.DS_Store文件。

现在他们将从存储库中删除,并在将来被忽略。注意:即使您在本地使用了 git rm --cached ,它也会为其他人删除文件。不幸的是,关于这一点你可以做的不多。此外,这些文件仍然存在于您的历史记录中,因此根据您的操作,您可能会在其他分支中看到它们,直到合并并且所有分支机构都基于具有新提交的内容。


In Xcode I noticed that .DS_Store and *.xcuserstate always change and don't need to be commited. So, I wrote a .gitignore file that contains this:

.DS_Store
*.xcuserstate

among other entries. Then I used:

git rm --cached *xcuserstate
git rm ---cached .DS_Store

To remove the these file types already under version control. However, when I go to merge Xcode tells me that there are changes that need to be committed. Those changes include .DS_Store files and .xcuserstate files.

So, I tried this:How can I Remove .DS_Store files from a Git repository?

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
find . -name *.xcuserstate -print0 | xargs -0 git rm --ignore-unmatch

and I got the same result. How do I remove these files from source control for good?

解决方案

You need to commit your change after removing them from the staging area.

As you did already, run:

$ git rm --cached path/to/.DS_Store
$ git rm --cached *.xcuserstate

Note, you may have some in other directories, so you may need several invocations to get them all. At this point, your removals are staged in the index, but there's still more to do: add your .gitignore, and commit the final result:

$ git add .gitignore
$ git commit -m "Remove and ignore .xcuserstate and .DS_Store files."

Now they'll be removed from the repository, and ignored in the future. Note: this will remove the files for other people, even though you used git rm --cached locally. Unfortunately, there isn't much you can do about this. Also, the files are still in your history, so depending on what you do, you may see them in other branches until things get merged and all your branches are based on something that has the new commit.

这篇关于从git中删除.xcuserstate和DS_Store文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆