我已经做了几个月的iOS开发了,刚刚了解到有前途的用于依赖管理的CocoaPods库。
我在一个个人项目中尝试过:在我的Podfile中添加了对Kiwi的依赖,运行pod install CocoaPodsTest。Xcodeproj,瞧,它工作得很好。
我唯一想知道的是:我要签入什么,为了版本控制我要忽略什么?似乎很明显,我想签入Podfile本身,也可能是.xcworkspace文件;但是我是否忽略了Pods/目录?是否还会生成其他文件(当我添加其他依赖项时),也应该添加到.gitignore中?
我属于不签入库的开发人员阵营,假设我们在其他位置有一个好的副本可用。因此,在我的.gitignore中,我包含了以下针对CocoaPods的行:
Pods/
#Podfile.lock # changed my mind on Podfile.lock
Then I make sure that we have a copy of the libraries in a safe location. Rather than (mis-)use a project's code repository to store dependencies (compiled or not) I think the best way to do this is to archive builds. If you use a CI server for your builds (such as Jenkins) you can permanently archive any builds that are important to you. If you do all your production builds in your local Xcode, make a habit of taking an archive of your project for any builds you need to keep. Something like:
1. Product --> Archive
分配……提交到iOS应用商店/保存为企业或Ad-hoc部署/等等
在Finder中显示您的项目文件夹
右键压缩WhateverProject
这提供了整个项目的构建映像,包括用于构建应用程序的完整项目和工作区设置,以及二进制发行版(如Sparkle,专有sdk,如TestFlight等),无论他们是否使用CocoaPods。
更新:我已经改变了我的想法,现在提交Podfile。锁定源代码控制。然而,我仍然相信pod本身是构建工件,应该在源代码控制之外进行管理,通过另一种方法,如CI服务器或如上所述的存档过程。
我建议使用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.
我提交我的Pods目录。我不同意Pods目录是一个构建产物。事实上,我想说它绝对不是。它是应用程序源代码的一部分:没有它就无法构建!
我们更容易将CocoaPods视为开发工具,而不是构建工具。它不构建你的项目,它只是为你克隆和安装你的依赖项。为了能够简单地构建项目,不应该必须安装CocoaPods。
通过使CocoaPods成为构建的依赖项,您现在需要确保它在构建项目所需的任何地方都可用……团队管理员需要它,您的CI服务器需要它。通常,您应该始终能够克隆源存储库并进行构建,而不需要做任何进一步的工作。
如果你频繁切换分支,不提交pod目录也会造成巨大的麻烦。现在,每次切换分支时都需要运行pod install,以确保依赖项是正确的。当你的依赖关系稳定时,这可能不那么麻烦,但在项目早期,这是一个巨大的时间消耗。
我忽略了什么?什么都没有。Podfile,锁文件和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版本历史。
在一天结束的时候,如果你有一个紧迫的截止日期,预算紧张,时间是至关重要的——我们需要尽可能多的资源,不要把时间浪费在严格的意识形态上,而是利用一套工具一起工作——让我们的生活更容易、更有效。
检查舱。
我认为这应该成为软件开发的一个原则
所有构建都必须是可复制的
确保构建的唯一方法是
可复制性是指控制所有依赖关系;全部签到
因此,依赖性是必须的。
一个从头开始的新开发人员应该能够检查您的项目并开始工作。
Why?
CocoaPods或任何其他外部库可能会改变,这可能会破坏事情。或者它们可能会移动,或者被重新命名,或者完全被移除。你不能依赖互联网为你储存东西。你的笔记本电脑可能死机了,生产中有一个严重的bug需要修复。主要开发人员可能会被公共汽车撞到,而他的替代者不得不匆忙启动。我希望最后一个例子只是理论上的但它确实发生在我工作的一家初创公司。撕裂的声音。
现在,实际上,您不能真正检入所有依赖项。您不能检入用于创建构建的机器的映像;你不能检入编译器的确切版本。等等。有现实的限制。但是你要尽可能地检查——不这样做只会让你的生活更加艰难。我们不希望这样。
最后一句话:pod不是构建工件。构建构件是从构建中生成的。您的构建使用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.
最后取决于你采取的方法。
Cocoapods团队是这么想的:
是否检查您的Pods文件夹取决于您,因为
工作流程因项目而异。我们建议您保留
pod目录下的源代码控制,不要将它添加到您的
.gitignore。但最终这个决定取决于你。
就我个人而言,我想把Pods排除在外,如果我使用Node,就像node_modules,如果我使用Bower,就像bower_components。这适用于几乎所有的依赖管理器,也是git子模块背后的理念。
然而,有时你可能想要真正确定某个依赖项的最新状态,这样你才能在项目中拥有该依赖项。当然,如果您这样做,会有一些缺点,但这些问题不仅适用于Cocoapods,而且适用于任何依赖管理器。
下面是Cocoapods团队制作的利弊清单,以及之前提到的引文全文。
Cocoapods团队:我应该将Pods目录检入源代码控制吗?
.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的讨论。
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.
就个人而言,这取决于:
为什么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.
缺点:更大的存储库,令人困惑的差异(主要针对团队成员),潜在的冲突更多。
不签入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的想法,这减轻了缺点。
TL;DR:当你跟踪Pods/文件夹时,项目更容易
从。当你不跟踪它的时候,就更容易在时间上进行改进
你在一个团队中工作。
虽然Cocoapods组织鼓励我们跟踪Pods/目录,但他们说这取决于开发人员根据这些利弊来决定是否这样做:http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
就我个人而言,我通常只跟踪那些我暂时不会再做的项目的Pods/文件夹。这样,任何开发人员都可以快速地从中吸取教训,并使用合适的cocoapods版本继续工作。
另一方面,我认为当你不跟踪Pods/文件夹时,提交历史会变得更清晰,更容易合并代码和审查其他人的代码。我通常在安装cocoapod库时设置它的版本,以确保任何人都可以使用与我相同的版本安装项目。
此外,当pod /目录被跟踪时,所有开发人员都必须使用相同版本的Cocoapods,以防止每次我们运行pod install来添加/删除pod时更改数十个文件。
底线:当您跟踪Pods/文件夹时,项目更容易从其中获取。当你不追踪它的时候,就更容易改进。