开发者

How can I sanely approach version control and Core Data models?

开发者 https://www.devze.com 2023-01-05 11:50 出处:网络
When we put Core Data model files under version control with git, we always have a horrible time merging changes - the only sure fire way we\'ve found to avoid having to merge in changes by hand is to

When we put Core Data model files under version control with git, we always have a horrible time merging changes - the only sure fire way we've found to avoid having to merge in changes by hand is to communicate among the team to block off access to the model while one person makes t开发者_StackOverflowheir necessary changes and pushes, then the next person, etc. Surely there is a better way to handle this, but as a git novice no obvious solution comes to mind. Any suggestions?


While there is no way to get around the merging problem of core data models, I created a git diff driver for core data model files which should make things a bit easier (see README for instructions on how to set it up)

https://github.com/chaitanyagupta/XCDataModelPrinter

Once you've set up XCDataModelPrinter as your git-diff driver, you can do a few things to make merging a bit easier:

Review changes made to the model in our branch

git diff other-branch...my-branch -- /path/to/model

Review changes made to the model in the other branch

git diff my-branch...other-branch -- /path/to/model

After you've reviewed the changes, let's try and do the merge on our branch:

git merge other-branch

If git didn't report a merge conflict, then review the merge results (you will see a combined diff in this case)

git diff --cached /path/to/model

If the merge resulted in a conflict, there's one of two paths you can take: check out the model file in your own branch and manually add changes made to the other one, or vice-versa. Assuming you want to use the first path:

Check out model changes in our own branch:

git checkout --ours -- /path/to/model

Using the diff command above to see the changes made in the other-branch, manually add those changes and review:

git diff -- /path/to/model

Once you are satisfied, just git-add the model file so its no longer marked as unmerged, and commit:

git add /path/to/model
git commit


As far as I have seen, there is no saner way at this time because the model is stored in a format that does not lend itself to merging. Normally I do exactly what you do, have one person working on the model at a time to avoid collisions.


As soon as you start maintaining migration mapping models, at least you can compare data models and have a look at the changes. The same compare functionality would also be great within SCM revisions of data models and would make life a lot easier.

0

精彩评论

暂无评论...
验证码 换一张
取 消