简体   繁体   English

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

[英]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: 每当我合并其他团队成员的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

We never change the value of x, and we always give integer like value. 我们永远不会改变x的值,我们总是给出像值一样的整数。 Obviously, Xcode changed the value automatically. 显然,Xcode会自动更改该值。 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. 您可以通过说服Git文件内容没有更改来避免检查此类修改后的值。

That is possible with a clean script which will be in charge of keeping only an integer value for x. 这是可能的一个clean脚本,它将负责只保留x的整数值。
That script will be applied only to the .storyboard files (as described here ), and will have to replace "254.xxx" by "254". 该脚本将仅应用于.storyboard文件(如此处所述 ),并且必须将“254.xxx”替换为“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 . 通过该脚本恢复文件是通过内容过滤器驱动程序使用.gitattributes声明自动执行的

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

Once you declare that content filer driver in your local git config, it will automatically, on git commit , restore the file. 一旦在本地git配置中声明了该内容文件管理器驱动程序,它将自动在git commit恢复该文件。
Or it will consider the file as unchanged on git diff / git status , even when XCode modified that value. 或者它会在git diff / git status上将文件视为未更改,即使XCode修改了该值也是如此。

See a complete example in " Best practice - Git + Build automation - Keeping configs separate ". 请参阅“ 最佳实践 - Git +构建自动化 - 保持配置分离 ”中的完整示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM