CocoaPods 和 GitHub 分支 [英] CocoaPods and GitHub forks
问题描述
这是我第一次 fork GitHub 项目,我也不太擅长 CocoaPods,所以请多多包涵.
基本上,我在我的 Podfile
中使用以下内容在 GitHub 上创建了一个项目:
pod 'REActivityViewController', '~>1.6.7', :git =>'https://github.com/<用户名>/REActivityViewController.git'
然后我对 fork 进行了一些更改,当然,当我执行 pod install
以安装另一个 pod 时,它重新安装了原始的 REActivityViewController
并删除了我的更改.
我意识到我需要在另一个 pod install
之前将我的更改推送到我的 fork,但是考虑到这是由 CocoaPods 安装的 repo,我怎么知道它是正在安装的 fork?我查看了安装在 Pods
文件夹下的 REActivityViewController
文件夹,没有任何 git 文件.
我是否需要在我的项目之外处理我的 fork,然后使用 CocoaPods 来安装更改?这太繁琐的工作流程了.
或者我需要对子模块做些什么?
我会用一个例子来回答这个问题.我有一个 TTTAttributedLabel 的分支,其中添加了一些额外的功能:
<块引用>https://github.com/getaaron/TTTAttributedLabel
为了在 Cocoapods 项目中使用它,我:
- 将我的更改推送到我的 fork
- 配置我的 Podfile 以获取更改 &更新
将更改推送到 fork 后,获取上次提交的 SHA.你可以使用 git rev-parse origin/master | 来做到这一点.pbcopy
或您项目的 GitHub 提交页面:
然后,您可以在您的 Podfile 中指定您的 fork 上的特定提交,如下所示:
pod 'TTTAttributedLabel', :git =>'https://github.com/getaaron/TTTAttributedLabel.git', :commit =>'d358791c7f593d6ea7d6f8c2cac2cf8fae582bc1'
之后,pod update
将从你的 fork 更新这个特定的提交.如果你愿意,你也可以为你的 fork 创建一个 podspec
,但我发现这种方法更简单,而且我不会频繁地进行更改以证明新工作流程的合理性.
我是否需要在我的项目之外处理我的 fork,然后使用 Cocoapods 来安装更改?这是繁琐的工作流程的方式.
你可以这样做,但我通常:
- 编辑我的项目中的代码并确保它有效
- 将更改复制到我的 fork,通过
- 导出补丁,或
- 复制整个源代码文件
- 提交 &推送到 GitHub
- 使用新的 SHA 更新 Podfile
- 运行
pod update
.
<块引用>
或者我需要对子模块做些什么?
不,你不需要.
This is my first time forking a GitHub project, and I'm not too competent with CocoaPods either, so please bear with me.
Basically, I forked a project on GitHub using the following in my Podfile
:
pod 'REActivityViewController', '~> 1.6.7', :git => 'https://github.com/<username>/REActivityViewController.git'
I then made some changes to the fork, and of course when I did a pod install
to install another pod it reinstalled the original REActivityViewController
and erased my changes.
I'm realizing I need to push my changes to my fork before another pod install
, but how do I know it is the fork being installed, considering that this is a repo installed by CocoaPods? I looked in the REActivityViewController
folder installed under the Pods
folder and there aren't any git files.
Do I need to work on my fork outside of my project and then use CocoaPods to install the changes? That's too cumbersome of a workflow.
Or do I need to do something with submodules?
I will answer this question using an example. I have a fork of TTTAttributedLabel with some extra functionality I added here:
In order to use this in a Cocoapods project, I:
- Push my changes to my fork
- Configure my Podfile to get the changes & update
Once you've pushed your changes to your fork, get the SHA of your last commit. You can do this using git rev-parse origin/master | pbcopy
or on the GitHub commits page for your project:
Then, you can specify the specific commit on your fork in your Podfile like this:
pod 'TTTAttributedLabel', :git => 'https://github.com/getaaron/TTTAttributedLabel.git', :commit => 'd358791c7f593d6ea7d6f8c2cac2cf8fae582bc1'
After that, pod update
will update this particular commit from your fork. If you want, you can also make a podspec
for your fork, but I find this approach simpler and I don't make changes frequently enough to justify a new workflow.
Do I need to work on my fork outside of my project and then use Cocoapods to install the changes? That's way to cumbersome of a workflow.
You can do it this way, but I usually:
- Edit the code inside my project and make sure it works
- Copy the changes over to my fork, by
- exporting a patch, or
- copying over the entire source code file
- Commit & push to GitHub
- Update the Podfile with the new SHA
- Run
pod update
.
Or do I need to do something with submodules?
No, you don't need to.
这篇关于CocoaPods 和 GitHub 分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!