6

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?

Yi Jiang
  • 3,938
  • 6
  • 30
  • 62

1 Answers1

3

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".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I was testing the regex here https://regex101.com/ but whatever i put `254.987` or `"254.987"` or `x="254.987"` it doesnt transform it to `254` but it transform it to the same input i give, any idea why? – denis_lor Mar 14 '19 at 08:23
  • @denis_lor can you share the regex101.com link to the specific regex and test you were using? – VonC Mar 14 '19 at 13:20
  • @denis_lor I have edited the answer and fixed the regex: https://regex101.com/r/9BR5BC/1 – VonC Mar 14 '19 at 13:24
  • doesn't work if you put `x="254.987"testtest` it highlights everything, also `testtest` – denis_lor Mar 14 '19 at 13:26
  • 1
    @denis_lor That will work with the regex in the answer, which I have reported in https://regex101.com/r/9BR5BC/2. – VonC Mar 14 '19 at 13:36