github/gitignore · Swift.gitignore

Swift .gitignore 模板详解

说明 Swift.gitignore 忽略 xcuserdata、应用打包文件、Swift Package Manager 的 .build、Carthage 构建以及 fastlane 产物的原因,以及 CocoaPods、Package.resolved 的判断标准。

在生成器中打开 与 macOS, Xcode, Objective-C 一起打开

Swift.gitignore 面向用 Xcode 开发 iOS、macOS 应用,或用 Swift Package Manager 开发包的项目。它处理 Xcode 的用户专属状态和发布文件、依赖管理工具(SwiftPM、Carthage、CocoaPods)的构建结果以及 fastlane 报告。

模板中有许多被注释掉的可选规则。像 Pods/Packages/Package.resolved*.xcworkspace 这类是否提交取决于团队方针的项目,默认不忽略,交由团队判断。

逐条规则详解

模式忽略什么,为什么忽略
xcuserdata/用户专属 Xcode 状态方案选择、断点、窗口布局等因开发者而异的设置保存在 .xcodeproj.xcworkspace 中的 xcuserdata 里。共享它会导致彼此的设置不断被覆盖。
*.hmap头文件映射Xcode 在构建过程中生成的用于头文件搜索的文件。
*.ipa*.dSYM.zip*.dSYM应用打包用于发布的应用归档和用于崩溃分析的符号文件。每次构建都会重新生成,而且体积很大。dSYM 应上传到崩溃报告服务保存。
timeline.xctimelineplayground.xcworkspacePlaygroundSwift Playground 运行时生成的时间线和内部工作区。
.build/Swift Package Managerswift build 存放依赖检出和编译结果的目录,随时可以重新生成。
Carthage/Build/CarthageCarthage 构建的框架。源码检出(Carthage/Checkouts)只以注释形式保留,供自行选择。
fastlane/report.xmlfastlane/Preview.htmlfastlane/screenshots/**/*.pngfastlane/test_outputfastlanefastlane 的运行报告和截图。正如模板注释所说,建议在需要时重新生成截图。

实践中的注意事项

原始模板

Swift.gitignore规则 13 行
# Xcode## gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore## User settingsxcuserdata/## Obj-C/Swift specific*.hmap## App packaging*.ipa*.dSYM.zip*.dSYM## Playgroundstimeline.xctimelineplayground.xcworkspace# Swift Package Manager## Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.# Packages/# Package.pins# Package.resolved# *.xcodeproj## Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata# hence it is not needed unless you have added a package configuration file to your project# .swiftpm.build/# CocoaPods## We recommend against adding the Pods directory to your .gitignore. However# you should judge for yourself, the pros and cons are mentioned at:# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control## Pods/## Add this line if you want to avoid checking in source code from the Xcode workspace# *.xcworkspace# Carthage## Add this line if you want to avoid checking in source code from Carthage dependencies.# Carthage/CheckoutsCarthage/Build/# fastlane## It is recommended to not store the screenshots in the git repo.# Instead, use fastlane to re-generate the screenshots whenever they are needed.# For more information about the recommended setup visit:# https://docs.fastlane.tools/best-practices/source-control/#source-controlfastlane/report.xmlfastlane/Preview.htmlfastlane/screenshots/**/*.pngfastlane/test_output

模板来源: github/gitignore/Swift.gitignore @356fd7b (2026-09-11) · CC0-1.0

常搭配使用的模板

其他模板详解