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

后端 未结 3 1877
悲&欢浪女
悲&欢浪女 2021-02-15 15:36

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 i

相关标签:
3条回答
  • 2021-02-15 16:06

    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
    
    0 讨论(0)
  • 2021-02-15 16:13

    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 讨论(0)
  • 2021-02-15 16:15

    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.

    0 讨论(0)
提交回复
热议问题