Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode change storyboard's frame value automatically cause git merge conflict all the time. How to solve it?

Every time when I merge other team member's iOS objc project, I got some strange conflict like this:

<<<<<<< HEAD
    <rect key="frame" x="254.00000003476939" y="0.0" width="63" height="21"/>
=======
    <rect key="frame" x="254.00000010362709" y="0.0" width="63" height="21"/>
>>>>>>> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

We never change the value of x, and we always give integer like value. Obviously, Xcode changed the value automatically. How to prevent this kind things happen?

like image 904
Yi Jiang Avatar asked Oct 28 '14 00:10

Yi Jiang


1 Answers

You could avoid checking in such modified value by convincing Git that the file content has not changed.

That is possible with a clean script which will be in charge of keeping only an integer value for x.
That script will be applied only to the .storyboard files (as described here), and will have to replace "254.xxx" by "254".

 sed -i 's/x=\"([0-9]+).*\"/x=\"\1\"/g'

The restoration of the file through that script is automated through a content filter driver, using a .gitattributes declaration.

https://i.stack.imgur.com/tumAc.png
(image from "Customizing Git - Git Attributes" from "Pro Git book"))

Once you declare that content filer driver in your local git config, it will automatically, on git commit, restore the file.
Or it will consider the file as unchanged on git diff/git status, even when XCode modified that value.

See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

like image 128
VonC Avatar answered Nov 15 '22 05:11

VonC