我已经做了几个月的iOS开发了,刚刚了解到有前途的用于依赖管理的CocoaPods库。
我在一个个人项目中尝试过:在我的Podfile中添加了对Kiwi的依赖,运行pod install CocoaPodsTest。Xcodeproj,瞧,它工作得很好。
我唯一想知道的是:我要签入什么,为了版本控制我要忽略什么?似乎很明显,我想签入Podfile本身,也可能是.xcworkspace文件;但是我是否忽略了Pods/目录?是否还会生成其他文件(当我添加其他依赖项时),也应该添加到.gitignore中?
我属于不签入库的开发人员阵营,假设我们在其他位置有一个好的副本可用。因此,在我的.gitignore中,我包含了以下针对CocoaPods的行:
Pods/
#Podfile.lock # changed my mind on Podfile.lock
Then I make sure that we have a copy of the libraries in a safe location. Rather than (mis-)use a project's code repository to store dependencies (compiled or not) I think the best way to do this is to archive builds. If you use a CI server for your builds (such as Jenkins) you can permanently archive any builds that are important to you. If you do all your production builds in your local Xcode, make a habit of taking an archive of your project for any builds you need to keep. Something like:
1. Product --> Archive
分配……提交到iOS应用商店/保存为企业或Ad-hoc部署/等等
在Finder中显示您的项目文件夹
右键压缩WhateverProject
这提供了整个项目的构建映像,包括用于构建应用程序的完整项目和工作区设置,以及二进制发行版(如Sparkle,专有sdk,如TestFlight等),无论他们是否使用CocoaPods。
更新:我已经改变了我的想法,现在提交Podfile。锁定源代码控制。然而,我仍然相信pod本身是构建工件,应该在源代码控制之外进行管理,通过另一种方法,如CI服务器或如上所述的存档过程。
不签入pod /版本控制的优点(按重要性的主观顺序):
Much easier to merge commits, and review code diffs. Merging is a common source of issues in a code base, and this allows you to focus only on things that are pertinent.
It's impossible for some random contributor to edit the dependencies themselves and check the changes in, which they should never do (and again would be hard to identify if the diff is massive). Editing dependencies is very bad practice because a future pod install could occlude the changes.
Discrepancies between the Podfile and the Pods/ directory are found quicker among teammates. If you check in Pods/ and, for example, update a version in the Podfile, but forget to run pod install or check in the changes to Pods/, you will have a much harder time noticing the source of the discrepancy. If Pods/ isn't checked in, you always need to run pod install anyway.
Smaller repo size. Having a smaller byte-footprint is nice, but that doesn't matter much in the grand scheme. More importantly: having more things in the repo also increases your cognitive load. There is no reason to have things in the repo that you shouldn't be looking at. Refer to documentation (the abstraction) to know how something works, not at code (the implementation).
Easier to discern how much someone contributes (since their lines of code contributed won't include dependencies they didn't write)
JAR files, .venv/ (virtual environments), and node_modules/ are never included in version control. If we were completely agnostic about the question, not checking in Pods would be the default based on precedent.
不检查pod的缺点/
切换分支或还原提交时必须运行pod install。
您不能仅仅通过克隆存储库来运行项目。您必须安装pod工具,然后运行pod install。
你必须有互联网连接才能运行pod install,而且pod的源代码必须可用。
如果依赖的所有者删除了他们的包,你就不能使用它(尽管你一开始就不应该使用已弃用的依赖——这只会迫使你更早地进行依赖卫生)。
总之,不包含Pods目录是防止更多不良做法的屏障。包含Pods目录可以使项目更容易运行。比起后者,我更喜欢前者。如果一开始就不存在犯某些错误的可能性,那么你就不需要向项目中的每个新人汇报“什么不能做”。我也喜欢有一个单独的版本控制Pods的想法,这减轻了缺点。