我应该将.swiftpm添加到gitignore吗?
在 Xcode 中编辑 Swift 包时会创建一个 .swiftpm 目录。我应该通过添加到我的 .gitignore 来忽略这个目录吗?
回答
根据Swift 论坛中的这篇文章,该.swiftpm目录“旨在作为对包进行操作的工具的地方,用于存储自己的状态或配置文件,用户不应将其作为源直接编辑” - 它不是 Xcode 独有的支持。因此,将它添加到 .gitignore 可能比仅仅忽略 Xcode 文件产生更大的影响。
您可以考虑忽略.swiftpm/xcode,但这也不是普遍推荐的,因为 Xcode 将共享方案存储在那里,正如在这个被拒绝的 pull request 中提到的。
默认情况下,Swift Package Manager 添加xcuserdata/到.gitignore,这是将 SPM 与 Xcode 一起使用所需的主要忽略。
- I spent hours wondering why my CI wouldn't work having a misterious xcodebuild and git error like so `xcodebuild: error: Could not resolve package dependencies:` ... `fatal: Needed a single revision` It was indeed happenning because the schemes created by xcode (in `.swiftpm/xcode/`) wouldn't be add/commit to the repository... Finally found the problem -_- choose wisely what to ignore and be curious is the lesson here.