我已经做了几个月的iOS开发了,刚刚了解到有前途的用于依赖管理的CocoaPods库。
我在一个个人项目中尝试过:在我的Podfile中添加了对Kiwi的依赖,运行pod install CocoaPodsTest。Xcodeproj,瞧,它工作得很好。
我唯一想知道的是:我要签入什么,为了版本控制我要忽略什么?似乎很明显,我想签入Podfile本身,也可能是.xcworkspace文件;但是我是否忽略了Pods/目录?是否还会生成其他文件(当我添加其他依赖项时),也应该添加到.gitignore中?
就个人而言,这取决于:
为什么pod应该是repo的一部分(在源代码控制下)并且不应该被忽略
The source is identical
You can build it right away as is (even without the cocoapods)
Even if a pod is deleted, we still have its copy (Yes, this can happen and it did. In an old project where you want just a small change you would need to implement a new library to be able to even build).
pods.xcodeproj settings are part of the source control as well. This means e.g. if you have the project in swift 4, but some pods must be in swift 3.2 because they are not updated yet, these settings will be saved. Otherwise the one who cloned the repo would end up with errors.
You can always delete pods from the project and run pod install, the opposite can not be done.
Even the authors of the Cocoapods recommend it.
缺点:更大的存储库,令人困惑的差异(主要针对团队成员),潜在的冲突更多。
我提交我的Pods目录。我不同意Pods目录是一个构建产物。事实上,我想说它绝对不是。它是应用程序源代码的一部分:没有它就无法构建!
我们更容易将CocoaPods视为开发工具,而不是构建工具。它不构建你的项目,它只是为你克隆和安装你的依赖项。为了能够简单地构建项目,不应该必须安装CocoaPods。
通过使CocoaPods成为构建的依赖项,您现在需要确保它在构建项目所需的任何地方都可用……团队管理员需要它,您的CI服务器需要它。通常,您应该始终能够克隆源存储库并进行构建,而不需要做任何进一步的工作。
如果你频繁切换分支,不提交pod目录也会造成巨大的麻烦。现在,每次切换分支时都需要运行pod install,以确保依赖项是正确的。当你的依赖关系稳定时,这可能不那么麻烦,但在项目早期,这是一个巨大的时间消耗。
我忽略了什么?什么都没有。Podfile,锁文件和Pods目录都被提交。相信我,这会帮你省去很多麻烦。缺点是什么?更大一点的回购?又不是世界末日。
.gitignore file
没有答案真的提供了。gitignore,所以这里有两种口味。
在Pods目录中检查(好处)
Xcode/iOS友好的git忽略,跳过Mac OS系统文件,Xcode,构建,其他存储库和备份。
. gitignore:
# Mac OS X Finder
.DS_Store
# Private Keys
*.pem
# Xcode legacy
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
# Xcode
xcuserdata/
project.xcworkspace/
DerivedData/
# build products
build/
*.[oa]
# repositories
.hg
.svn
CVS
# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/
忽略Pods目录(好处)
.gitignore:(附加到前面的列表)
# Cocoapods
Pods/
不管你是否检查Pods目录,Podfile和Podfile。Lock应该始终保持在版本控制之下。
如果pod没有签入,您的Podfile可能需要为每个Cocoapod请求明确的版本号。Cocoapods.org的讨论。