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

后端 未结 3 1954
悲&欢浪女
悲&欢浪女 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
    

提交回复
热议问题