.gitignore文件中忽略xcuserdata文件夹内的所有内容,但不包括xcuserstate文件。

46

我正在一个 Xcode 项目中工作,尝试配置 .gitignore 文件以排除 xcuserdata 文件夹内的所有内容。

以下是我的 .gitignore 文件:

# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
xcuserdata/*

但每次构建/运行项目并执行git status时,它仍然显示以下修改的文件:

modified: MyProject.xcodeproj/project.xcworkspace/xcuserdata/fernando.xcuserdatad/UserInterfaceState.xcuserstate

有人知道出了什么问题吗?


这个回答解决了你的问题吗?无法忽略UserInterfaceState.xcuserstate - Alex Cohn
12个回答

52

我找到了解决方法

问题不在于.gitignore文件

问题在于UserInterfaceState.xcuserstate未从git服务器中移除,我在以下链接中找到了解决方法:

无法忽略UserInterfaceState.xcuserstate


1
只需运行此命令,即可忽略任何之前保存或暂存的文件:git rm --cached FILE_TO_REMOVE。因为缓存文件将绕过.gitignore配置。 - NFerocious

13

附加信息

我也遇到过这个问题,似乎在提交后.gitignore仍然会将它们添加进来。 我所添加的内容对我有效。

...... 这不能被 .gitignore 读取:

xcuserdata/*

加入这个对我来说有效:

*xcworkspace/xcuserdata/*

或者阅读:

*/xcuserdata/*

2
*xcworkspace/xcuserdata/* 对我有用!谢谢! - Leonard
当然。如果您之前提交了该文件,那么您还应该从缓存中删除它。 - NFerocious
这些对我都不起作用。但只有xcuserdata,没有其他内容可以忽略它。 - alekop

10
除了将*.xcuserstate添加到您的.gitignore文件中之外,还需要记得删除缓存的*.xcuserstategit rm --cached [YourProjectName].xcodeproj/project.xcworkspace/xcuserdata/[ YourUsername].xcuserdatad/UserInterfaceState.xcuserstate 更多信息请参见:https://www.programmersought.com/article/1594916500/

4

对我而言,唯一管用的是将也包含.xcuserdata的Pods提交到仓库中:

**/xcuserdata/*

3

我看不到这里有任何的逻辑。 然而,在我的情况下,只有将 xcuserdata/ 移到.gitignore文件的最底部才有效。


3
如果您使用git,可以添加 .gitignore 文件。
# Xcode
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.moved-aside
DerivedData
.idea/
*.xccheckout
*.moved-aside
xcuserdata/
*.hmap
*.ipa
*.xcworkspace
*.xcuserstate // <--- Here
!default.xcworkspace

1

对我来说没有任何作用,但是请将以下行添加到您的gitignore文件中

*.xcuserdata

1

0

你可以简单地这样做

 git checkout -- <file>..." to discard changes in working directory

例子:

   modified:
        mySwa.com.xcworkspace/xcuserdata/bibscy.xcuserdatad/UserInterfaceState.xcuserstate

   git checkout -- mySwa.com.xcworkspace/xcuserdata/bibscy.xcuserdatad/UserInterfaceState.xcuserstate

0

顺便说一下,我的xcuserdata文件夹尚未被git跟踪,但仍然出现在git status中。问题是我在.gitignore文件中的xcuserdata前面有一个空格。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接