我已经做了几个月的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”目录作为一个git子模块/单独的项目似乎是一种很好的结构方式,原因如下。

在项目回购中使用pod,当与多个开发人员一起工作时,可能会在pull请求中造成非常大的差异,几乎不可能看到人们更改的实际工作(想象一下库更改了数百到数千个文件,而实际项目中只更改了少数文件)。 我看到了不向git提交任何东西的问题,因为拥有库的人可以随时删除它,而你实际上是SOL,这也解决了这个问题。

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

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

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

理论上,您应该在Pods目录中进行检查。在实践中,这并不总是有效的。许多pod都超过了github文件的大小限制,所以如果你使用github,你将会在检查pods目录时遇到问题。

我必须说,我是将pod提交到存储库的粉丝。按照前面提到的链接,你会得到一个很好的。gitignore文件来启动你的iOS Xcode项目,以允许Pods,但如果你愿意,你也可以轻松地排除它们:https://github.com/github/gitignore/blob/master/Objective-C.gitignore

我之所以热衷于将pod添加到存储库中,有一个根本原因,但似乎没有人注意到,如果我们的项目如此依赖的库突然从网络上删除了,会发生什么?

Maybe the host decides they no longer want to keep their GitHub account open What happens if the library is say several years old (like older than 5 years for example) there is a high risk the project may no longer be available at source Also another point, what happens if the URL to the repository changes? Lets say the person serving the Pod from their GitHub account, decides to represent themselves under a different handle - your Pods URLs are going to break. Finally another point. Say if you're a developer like me who does a lot of coding when on a flight between countries. I do a quick pull on the 'master' branch, do a pod install on that branch, while sitting in the airport and have myself all set for the upcoming 8 hour flight. I get 3 hours into my flight, and realise I need to switch to another branch.... 'DOH' - missing Pod information which is only available on the 'master' branch.

NB……请注意,用于开发的“主”分支只是举个例子,很明显,版本控制系统中的“主”分支应该保持干净,并且在任何时候都可以部署/构建

我认为从这些方面来看,在代码存储库中创建快照肯定比严格限制存储库大小要好。如前所述,播客文件。锁文件-而版本控制将给你一个良好的Pod版本历史。

在一天结束的时候,如果你有一个紧迫的截止日期,预算紧张,时间是至关重要的——我们需要尽可能多的资源,不要把时间浪费在严格的意识形态上,而是利用一套工具一起工作——让我们的生活更容易、更有效。

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.