How can I reasonably approach version control and Core Data moderators?

When we put Core Data model files under version control using git, we always have terrible time merges - the only sure way we have found to avoid having to merge the changes manually is by connecting the team to block access to the model, while how one person makes the necessary changes and pushes, then the next person, etc. Of course, there is a better way to handle this, but as a beginner git there is no obvious solution. Any suggestions?

+7
git version-control core-data
source share
3 answers

As far as I saw, there is currently no more robust way, because the model is stored in a format that cannot be merged. Usually I do exactly what you do so that one person works on the model at the same time to avoid collisions.

+3
source share

While there is no way to get around the problem of merging basic data models, I created a git comparison driver for master data model files that should make things a little easier (see README for configuration instructions)

https://github.com/chaitanyagupta/XCDataModelPrinter

Once you have installed XCDataModelPrinter as the git-diff driver, you can do a few things to simplify the merge:

View the changes made to the model in our branch

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

View changes made to the model in another branch

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

After you review the changes, try merging in our branch:

 git merge other-branch 

If git did not report a merge conflict, view the merge results (in this case you will see a combined diff)

 git diff --cached /path/to/model 

If the merge leads to a conflict, you can take one of two ways: check the model file in your branch and manually add the changes made to the other, or vice versa. Assuming you want to use the first path:

Check out the model changes in our own thread:

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

Using the diff command above to see the changes made in another branch, manually add these changes and view:

 git diff -- /path/to/model 

Once you are satisfied, simply git-add the model file so that it is no longer marked as unmerged and does:

 git add /path/to/model git commit 
+3
source share

Once you start saving migration mapping models, at least you can compare data models and look at the changes. The same comparison functionality will also be great in revising SCM models and will make life a lot easier.

+1
source share

All Articles