我已经做了几个月的iOS开发了,刚刚了解到有前途的用于依赖管理的CocoaPods库。

我在一个个人项目中尝试过:在我的Podfile中添加了对Kiwi的依赖,运行pod install CocoaPodsTest。Xcodeproj,瞧,它工作得很好。

我唯一想知道的是:我要签入什么,为了版本控制我要忽略什么?似乎很明显,我想签入Podfile本身,也可能是.xcworkspace文件;但是我是否忽略了Pods/目录?是否还会生成其他文件(当我添加其他依赖项时),也应该添加到.gitignore中?


当前回答

我提交我的Pods目录。我不同意Pods目录是一个构建产物。事实上,我想说它绝对不是。它是应用程序源代码的一部分:没有它就无法构建!

我们更容易将CocoaPods视为开发工具,而不是构建工具。它不构建你的项目,它只是为你克隆和安装你的依赖项。为了能够简单地构建项目,不应该必须安装CocoaPods。

通过使CocoaPods成为构建的依赖项,您现在需要确保它在构建项目所需的任何地方都可用……团队管理员需要它,您的CI服务器需要它。通常,您应该始终能够克隆源存储库并进行构建,而不需要做任何进一步的工作。

如果你频繁切换分支,不提交pod目录也会造成巨大的麻烦。现在,每次切换分支时都需要运行pod install,以确保依赖项是正确的。当你的依赖关系稳定时,这可能不那么麻烦,但在项目早期,这是一个巨大的时间消耗。

我忽略了什么?什么都没有。Podfile,锁文件和Pods目录都被提交。相信我,这会帮你省去很多麻烦。缺点是什么?更大一点的回购?又不是世界末日。

其他回答

是否检入Pods文件夹取决于您,因为工作流程因项目而异。我们建议您将Pods目录置于源代码控制之下,不要将其添加到.gitignore中。但最终这个决定取决于你:

签入Pods目录的好处

克隆repo之后,项目可以立即构建和运行,甚至不需要在机器上安装CocoaPods。不需要运行pod install,也不需要连接互联网。 Pod构件(代码/库)总是可用的,即使Pod的源(例如GitHub)宕机。 克隆repo后,Pod工件保证与原始安装中的工件相同。

忽略Pods目录的好处

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.

我通常在客户端的应用程序上工作。在这种情况下,我也将Pods目录添加到repo中,以确保在任何给定的时间,任何开发人员都可以进行签出、构建和运行。

如果这是我们自己的应用程序,我可能会排除Pods目录,直到我有一段时间不会使用它。

事实上,我必须得出结论,相对于纯用户的观点,我可能不是回答你的问题的最佳人选:)我会在https://twitter.com/CocoaPodsOrg上发布关于这个问题的推文。

检查舱。

我认为这应该成为软件开发的一个原则

所有构建都必须是可复制的 确保构建的唯一方法是 可复制性是指控制所有依赖关系;全部签到 因此,依赖性是必须的。 一个从头开始的新开发人员应该能够检查您的项目并开始工作。

Why?

CocoaPods或任何其他外部库可能会改变,这可能会破坏事情。或者它们可能会移动,或者被重新命名,或者完全被移除。你不能依赖互联网为你储存东西。你的笔记本电脑可能死机了,生产中有一个严重的bug需要修复。主要开发人员可能会被公共汽车撞到,而他的替代者不得不匆忙启动。我希望最后一个例子只是理论上的但它确实发生在我工作的一家初创公司。撕裂的声音。

现在,实际上,您不能真正检入所有依赖项。您不能检入用于创建构建的机器的映像;你不能检入编译器的确切版本。等等。有现实的限制。但是你要尽可能地检查——不这样做只会让你的生活更加艰难。我们不希望这样。

最后一句话:pod不是构建工件。构建构件是从构建中生成的。您的构建使用Pods,而不是生成它们。我都不知道为什么要讨论这个问题。

就我个人而言,我不检查Pods目录和内容。我不能说我花了很长时间来考虑这些影响,但我的推理是这样的:

Podfile引用了每个依赖项的特定标记或提交,因此pod本身可以从Podfile生成,因此它们更像一个中间构建产品而不是源代码,因此,在我的项目中不需要版本控制。

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.