xcode 当 pod 的新版本可用时,`pod update` 会覆盖我的代码更改吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16613464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:23:57  来源:igfitidea点击:

Will `pod update` overwrite my code changes when a new version of the pod is available?

iosxcodecocoapods

提问by Jon

I've added MKStoreKit version 4.99 to my project using cocoapods. My Podfile consists of:

我已经使用 cocoapods 将 MKStoreKit 版本 4.99 添加到我的项目中。我的 Podfile 包括:

platform :ios, '6.0'
pod 'MKStoreKit', '~> 4.99'

MKStoreKit has a configuration file called MKStoreKitConfigs.h that needs to be modified on a per-project basis, and I've modified the file appropriately. What will happen when MKStoreKit releases a new version, say 5.0, and I execute pod update? Will my changes be overwritten? Could you describe why yes or why no?

MKStoreKit 有一个名为 MKStoreKitConfigs.h 的配置文件,需要在每个项目的基础上进行修改,我已经适当地修改了该文件。当 MKStoreKit 发布新版本时会发生什么,比如 5.0,然后我执行pod update?我的更改会被覆盖吗?你能描述一下为什么是或为什么不是吗?

采纳答案by Marcel

Yes, pod update will overwrite your changes. What you could do is fork the project on Github make the changes in your fork and point Cocoapods to the fork. See Use a fork of Restkit on github via cocoaPod?on how to do that.

是的,pod update 将覆盖您的更改。你可以做的是在 Github 上 fork 项目,在你的 fork 中进行更改并将 Cocoapods 指向 fork。请参阅通过 cocoaPod 在 github 上使用 Restkit 的分支?关于如何做到这一点。

回答by Dmitry Zhukov

As I understand it's a known problem and also as one said: "this is kind of bad practice to configure 3rd party lib in header file".

据我所知,这是一个已知问题,正如有人所说:“在头文件中配置 3rd 方库是一种不好的做法”。

So at first you can take a look at this commit. IMO this is a better way to configure it.

所以首先你可以看看这个提交。IMO 这是配置它的更好方法。

Also you can add your fork as a Pod using:

您也可以使用以下命令将 fork 添加为 Pod:

pod 'MKStoreKit.MyFork', :path => 'MKStoreKit.MyFork.podspec'

EDIT: Thanks to rounakfor noticing, :localis now :path. From cocoapodsdocs:

编辑:感谢rounak的注意,:local现在是:path. 来自cocoapods文档:

Using this option (:path) CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project. This means that your edits will persist between CocoaPods installations. The referenced folder can be a checkout of your favourite SCM or even a git submodule of the current repo.

使用此选项 ( :path) CocoaPods 将假定给定文件夹是 Pod 的根目录,并将直接从 Pods 项目中的那里链接文件。这意味着您的编辑将在 CocoaPods 安装之间保持不变。引用的文件夹可以是您最喜欢的 SCM 的 checkout,甚至是当前 repo 的 git 子模块。

回答by gadu

This is an old post but I have a fairly simple workaround to keeping changes you make on Pods.

这是一篇旧帖子,但我有一个相当简单的解决方法来保留您对 Pod 所做的更改。

As mentioned, pod updatewill overwrite any changes you made. However, if you're using git what I like to do is commit all my changes except for my pod changes.

如前所述,pod update将覆盖您所做的任何更改。但是,如果您使用 git,我喜欢做的是提交除 pod 更改之外的所有更改。

Once the only changes I have on my branch are the Pods changes, I stash the pod changes by running git stash save "Custom Cocoapod changes, apply after every pod update". You can give it any message you'd like by changing the text between the "".

一旦我的分支上唯一的更改是 Pods 更改,我就会通过运行git stash save "Custom Cocoapod changes, apply after every pod update". 您可以通过更改“”之间的文本来给它任何您想要的消息。

This command has the side effect of reseting your working directory to the previous HEAD, so if you want to reapply those stashes you can just run git stash applyto get those changes back in, and then you can commit them to save them.

此命令具有将您的工作目录重置为之前的 HEAD 的副作用,因此如果您想重新应用这些存储,您只需运行git stash apply即可恢复这些更改,然后您可以提交它们以保存它们。

Don't use git stash popas this will delete the stash after applying it.

不要使用,git stash pop因为这会在应用后删除存储。

Now, at some undetermined time in the future, when you update your pods and its time to apply the stash again, what you're going to want to do is run git stash list. this will return a list of all the stashes you've made with the most recent being zero indexed. You'll probably see something like this:

现在,在未来某个不确定的时间,当您更新 Pod 并再次应用 stash 时,您要做的就是运行git stash list. 这将返回您制作的所有藏匿处的列表,其中最近的索引为零。你可能会看到这样的事情:

stash@{0}: On featureFooBar: foo bar
stash@{1}: On Master: Custom Cocoapod changes, apply after every pod update
...

If the custom cocoa pods changes stash is in stash@{0} then perfect, you can just run a git stash applyagain and you'll get those changes on your working directory. Otherwise once you find which stash number your pods changes are you can apply that stash by running git stash apply stash@{1}

如果自定义可可豆荚更改 stash 在 stash@{0} 中,那么完美,您只需git stash apply再次运行,您就会在工作目录中获得这些更改。否则,一旦您找到 Pod 更改的存储编号,您就可以通过运行来应用该存储git stash apply stash@{1}

Applying stashes is easiest when you have a clean working directory on the same branch but thats not required. This pagegives a good description of git stash and how to use it otherwise.

当您在同一分支上有一个干净的工作目录时,应用 stashes 是最简单的,但这不是必需的。这个页面很好地描述了 git stash 以及如何使用它。