Xcode 更改 storyboard 的 frame 值会一直自动导致 git merge 冲突.如何解决? [英] Xcode change storyboard's frame value automatically cause git merge conflict all the time. How to solve it?

查看:49
本文介绍了Xcode 更改 storyboard 的 frame 值会一直自动导致 git merge 冲突.如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次合并其他团队成员的iOS objc项目时,都会出现这样的奇怪冲突:

<代码><<<<<<<<<<<<头<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

我们从不改变 x 的值,我们总是给出类似整数的值.显然,Xcode 自动更改了该值.如何防止此类事情发生?

解决方案

你可以通过说服 Git 文件内容没有改变来避免签入这样修改过的值.

这可以通过 clean 脚本实现,该脚本只负责保留 x 的整数值.
该脚本将仅应用于 .storyboard 文件(如
(图片来自 "自定义 Git -Git 属性" 来自 "Pro Git book"))

一旦您在本地 git 配置中声明了内容文件管理器驱动程序,它就会在 git commit 上自动恢复文件.
或者它会认为文件在 git diff/git status 上没有改变,即使 XCode 修改了那个值.

请参阅最佳实践 - Git + 构建自动化 - 保持配置独立"中的完整示例.

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?

解决方案

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.


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

这篇关于Xcode 更改 storyboard 的 frame 值会一直自动导致 git merge 冲突.如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆