我已经做了几个月的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.
我建议使用GitHub的Objective-C gitignore。
具体来说,最佳实践是:
Podfile必须始终处于源代码控制之下。
Podfile。Lock必须始终处于源代码控制之下。
CocoaPods生成的工作区应该保持在源代码控制之下。
任何使用:path选项引用的Pod都应该保存在源代码控制下。
./Pods文件夹可以保存在源代码控制下。
要了解更多信息,您可以参考官方指南。
来源:我是CocoaPods核心团队的成员,就像@alloy一样
尽管Pods文件夹是一个构建工件,但在决定是否将其置于源代码控制之下时,您可能会考虑以下原因:
CocoaPods is not a package manager so the original source of the library could be removed in future by the author.
If the Pods folder is included in source control, it is not necessary to install CocoaPods to run the project as the checkout would suffice.
CocoaPods is still work in progress and there are options which don’t always lead to the same result (for example the :head and the :git options currently are not using the commits stored in the Podfile.lock).
There are less points of failure if you might resume work on a project after a medium/long amount of time.
不签入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的想法,这减轻了缺点。
我提交我的Pods目录。我不同意Pods目录是一个构建产物。事实上,我想说它绝对不是。它是应用程序源代码的一部分:没有它就无法构建!
我们更容易将CocoaPods视为开发工具,而不是构建工具。它不构建你的项目,它只是为你克隆和安装你的依赖项。为了能够简单地构建项目,不应该必须安装CocoaPods。
通过使CocoaPods成为构建的依赖项,您现在需要确保它在构建项目所需的任何地方都可用……团队管理员需要它,您的CI服务器需要它。通常,您应该始终能够克隆源存储库并进行构建,而不需要做任何进一步的工作。
如果你频繁切换分支,不提交pod目录也会造成巨大的麻烦。现在,每次切换分支时都需要运行pod install,以确保依赖项是正确的。当你的依赖关系稳定时,这可能不那么麻烦,但在项目早期,这是一个巨大的时间消耗。
我忽略了什么?什么都没有。Podfile,锁文件和Pods目录都被提交。相信我,这会帮你省去很多麻烦。缺点是什么?更大一点的回购?又不是世界末日。