我使用Git进行Xcode 4项目版本控制。我明确地添加了ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState。xcuserstate到.gitignore,但是Git不会忽略它。有人知道为什么吗?


当前回答

我觉得这样写比较好。

git rm——cache *//UserInterfaceState.xcuserstate**

其他回答

所有答案都很棒,但如果你在不同的Mac(家庭和办公室)上工作,这里有一个会为每个用户删除的答案

git rm --cache */UserInterfaceState.xcuserstate
git commit -m "Never see you again, UserInterfaceState"

如果您正在使用源树应用程序,这里有一个更简单的解决方案。 以下是使用说明

1.右键单击要添加到git忽略列表中的文件并选择停止跟踪。

再次右键单击相同的文件,你会注意到忽略选项现在启用,然后单击忽略按钮。

现在,您可以为同一个文件重置或提交更改,这取决于您的更改是否重要。将来所选文件的更改将不会被跟踪。

如果在做了上面提到的所有事情之后文件仍然显示,请确保Xcode设置中的这个复选框是未选中的:

对于xcode 8.3.3,我刚刚检查了上面的代码,并观察到,现在在这种情况下,我们必须将命令更改为这样

首先,您可以使用。gitignore文件

 touch .gitignore

之后,你可以使用这个命令删除所有的userInterface文件,通过使用这个命令,它将尊重你的.gitignore文件。

 git rm --cached [project].xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
 git commit -m "Removed file that shouldn't be tracked"

这里有一个关于如何递归地从git历史中删除有问题的文件的很好的解释:http://help.github.com/remove-sensitive-data/

非常有用,否则工具在试图显示那些不应该首先检查的巨大文件上的差异时往往会“挂起”……

以下是你可以做的(简而言之)来摆脱最大的东西:

cd YourProject
git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r YourProject.xcodeproj/project.xcworkspace' HEAD
# see what you want to do with your remote here...
# you can: git push origin master --force
# or you can delete it and push a fresh new one from your cleaned-up local...
rm -rf .git/refs/original
git gc --prune=now
git gc --aggressive --prune=now

对我来说非常有用:)