我已经做了几个月的iOS开发了,刚刚了解到有前途的用于依赖管理的CocoaPods库。
我在一个个人项目中尝试过:在我的Podfile中添加了对Kiwi的依赖,运行pod install CocoaPodsTest。Xcodeproj,瞧,它工作得很好。
我唯一想知道的是:我要签入什么,为了版本控制我要忽略什么?似乎很明显,我想签入Podfile本身,也可能是.xcworkspace文件;但是我是否忽略了Pods/目录?是否还会生成其他文件(当我添加其他依赖项时),也应该添加到.gitignore中?
Cocoapod文档中直接给出了答案。你可以看看“http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control”。
Whether or not you check in your Pods folder is up to you, as
workflows vary from project to project. We recommend that you keep the
Pods directory under source control, and don't add it to your
.gitignore. But ultimately this decision is up to you:
Benefits of checking in the Pods directory
After cloning the repo, the project can immediately build and run, even without having CocoaPods installed on the machine. There is no
need to run pod install, and no Internet connection is necessary.
The Pod artifacts (code/libraries) are always available, even if the source of a Pod (e.g. GitHub) were to go down.
The Pod artifacts are guaranteed to be identical to those in the original installation after cloning the repo.
Benefits of ignoring the Pods directory
The source control repo will be smaller and take up less space.
As long as the sources (e.g. GitHub) for all Pods are available, CocoaPods is generally able to recreate the same installation.
(Technically there is no guarantee that running pod install will fetch
and recreate identical artifacts when not using a commit SHA in the
Podfile. This is especially true when using zip files in the Podfile.)
There won't be any conflicts to deal with when performing source control operations, such as merging branches with different Pod
versions.
Whether or not you check in the Pods directory, the Podfile and
Podfile.lock should always be kept under version control.
最后取决于你采取的方法。
Cocoapods团队是这么想的:
是否检查您的Pods文件夹取决于您,因为
工作流程因项目而异。我们建议您保留
pod目录下的源代码控制,不要将它添加到您的
.gitignore。但最终这个决定取决于你。
就我个人而言,我想把Pods排除在外,如果我使用Node,就像node_modules,如果我使用Bower,就像bower_components。这适用于几乎所有的依赖管理器,也是git子模块背后的理念。
然而,有时你可能想要真正确定某个依赖项的最新状态,这样你才能在项目中拥有该依赖项。当然,如果您这样做,会有一些缺点,但这些问题不仅适用于Cocoapods,而且适用于任何依赖管理器。
下面是Cocoapods团队制作的利弊清单,以及之前提到的引文全文。
Cocoapods团队:我应该将Pods目录检入源代码控制吗?