I am working on a project using cocoapods and suddenly I see myself doing some changes in one of the libraries. How can I ensure that those changes will never be override by a <
For those looking for a simple solution, I have successfully solved this problem by using git stashes.
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 those 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.
This is not the most full proof solution since I can foresee some issues when you have multiple people on the same project, but it's a simple way to solve this without resorting to more involved solutions.