Xcode改变故事板的帧值自动导致git合并冲突。怎么解决?

问题描述 投票:6回答:1

每当我合并其他团队成员的iOS objc项目时,我都会遇到一些奇怪的冲突:

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

我们永远不会改变x的值,我们总是给出像值一样的整数。显然,Xcode会自动更改该值。如何防止这种事情发生?

xcode git uistoryboard
1个回答
3
投票

您可以通过说服Git文件内容没有更改来避免检查此类修改后的值。

这是可能的clean脚本,它将负责只保留x的整数值。 该脚本将仅应用于.storyboard文件(如described here),并且必须将“254.xxx”替换为“254”。

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

通过该脚本恢复文件是通过content filter driver使用.gitattributes declaration自动完成的。

https://i.stack.imgur.com/tumAc.png (图片来自"Customizing Git - Git Attributes"来自“Pro Git book”))

在本地git配置中声明该内容文件管理器驱动程序后,它将自动在git commit上恢复该文件。 或者它会在git diff / git status上将文件视为未更改,即使XCode修改了该值。

请参阅“Best practice - Git + Build automation - Keeping configs separate”中的完整示例。

© www.soinside.com 2019 - 2024. All rights reserved.