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

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

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


当前回答

我建议使用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.

其他回答

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.

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

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

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

.gitignore file

没有答案真的提供了。gitignore,所以这里有两种口味。


在Pods目录中检查(好处)

Xcode/iOS友好的git忽略,跳过Mac OS系统文件,Xcode,构建,其他存储库和备份。

. gitignore:

# Mac OS X Finder
.DS_Store

# Private Keys
*.pem

# Xcode legacy
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser

# Xcode
xcuserdata/
project.xcworkspace/
DerivedData/

# build products
build/
*.[oa]

# repositories
.hg
.svn
CVS

# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/

忽略Pods目录(好处)

.gitignore:(附加到前面的列表)

# Cocoapods
Pods/

不管你是否检查Pods目录,Podfile和Podfile。Lock应该始终保持在版本控制之下。

如果pod没有签入,您的Podfile可能需要为每个Cocoapod请求明确的版本号。Cocoapods.org的讨论。

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

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

将“Pods”目录作为一个git子模块/单独的项目似乎是一种很好的结构方式,原因如下。

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