xcode 从 git 中删除 .xcuserstate 和 DS_Store 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21868857/
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
Removing .xcuserstate and DS_Store files from git
提问by Bryan Bryce
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:
在 Xcode 中,我注意到 .DS_Store 和 *.xcuserstate 总是改变并且不需要提交。所以,我写了一个包含这个的 .gitignore 文件:
.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.
删除这些已受版本控制的文件类型。但是,当我去合并时 Xcode 告诉我需要提交更改。这些更改包括 .DS_Store 文件和 .xcuserstate 文件。
So, I tried this:How can I Remove .DS_Store files from a Git repository?
所以,我尝试了这个:如何从 Git 存储库中删除 .DS_Store 文件?
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?
我得到了同样的结果。如何从源代码管理中永久删除这些文件?
回答by John Szakmeister
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:
请注意,您可能在其他目录中有一些,因此您可能需要多次调用才能获得它们。此时,您的删除已在索引中暂存,但还有更多工作要做:添加您的.gitignore
,并提交最终结果:
$ 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 rm --cached
在本地使用,这也会删除其他人的文件。不幸的是,您对此无能为力。此外,这些文件仍然在您的历史记录中,因此根据您的操作,您可能会在其他分支中看到它们,直到合并所有分支并且您的所有分支都基于具有新提交的内容。
回答by user376507
Try git update-index --assume-unchanged *.xcuserstate .DS_Store
and see if it helps
试试看git update-index --assume-unchanged *.xcuserstate .DS_Store
是否有帮助