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

大城市里の小女人 提交于 2019-12-21 03:44:12

问题


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

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?


回答1:


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.




回答2:


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".

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

Also you can add your fork as a Pod using:

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

EDIT: Thanks to rounak for noticing, :local is now :path. From cocoapods docs:

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.




回答3:


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

As mentioned, pod update will 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.

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 "".

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 apply to get those changes back in, and then you can commit them to save them.

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

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:

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 apply again 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}

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



来源:https://stackoverflow.com/questions/16613464/will-pod-update-overwrite-my-code-changes-when-a-new-version-of-the-pod-is-ava

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!