xcode Git 和 pbxproj
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1549578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git and pbxproj
提问by DarthNerdus
I was looking at an open source Mac application, and they gave some suggested values for .gitignore. They were what I would expect...
我正在查看一个开源 Mac 应用程序,他们为 .gitignore 提供了一些建议值。他们是我所期望的......
However, they also suggested an entry into a .gitattributes file:
但是,他们还建议在 .gitattributes 文件中添加一个条目:
*.pbxproj -crlf -diff -merge
*.pbxproj -crlf -diff -merge
I'm not the most knowledgable in terms of git, so I was wondering - what exactly are the benefits of adding this line? What does do in particular? I've only seen this suggested in this one project, and if it was normal practice I would have expected to see it elsewhere right now. So I was curious about how it applies to the pbxproj file specifically.
我不是最了解 git 的人,所以我想知道 - 添加这一行到底有什么好处?具体做什么?我只在这个项目中看到了这个建议,如果这是正常做法,我现在希望在其他地方看到它。所以我很好奇它是如何专门应用于 pbxproj 文件的。
采纳答案by Grant Limberg
The pbxproj file isn't really human mergable. While it is plain ASCII text, it's a form of JSON. Essentially you want to treat it as a binary file.
pbxproj 文件并不是真正的人类可合并的。虽然它是纯 ASCII 文本,但它是 JSON 的一种形式。基本上你想把它当作一个二进制文件。
Here's what the individual flags do:
以下是各个标志的作用:
-crlf: don't use crlf <=> cr conversion
-crlf: 不要使用 crlf <=> cr 转换
-diff: do not diff the file
-diff:不区分文件
-merge: do not attempt to merge the file
-merge:不尝试合并文件
From the Pro Gitbook by Scott Chacon
来自Scott Chacon的Pro Git书
Some files look like text files but for all intents and purposes are to be treated as binary data. For instance, Xcode projects on the Mac contain a file that ends in .pbxproj, which is basically a JSON (plain text javascript data format) dataset written out to disk by the IDE that records your build settings and so on. Although it's technically a text file, because it's all ASCII, you don't want to treat it as such because it's really a lightweight database — you can't merge the contents if two people changed it, and diffs generally aren't helpful. The file is meant to be consumed by a machine. In essence, you want to treat it like a binary file.
有些文件看起来像文本文件,但出于所有意图和目的,它们都被视为二进制数据。例如,Mac 上的 Xcode 项目包含一个以 .pbxproj 结尾的文件,它基本上是一个 JSON(纯文本 javascript 数据格式)数据集,由 IDE 写出到磁盘,用于记录您的构建设置等。虽然它在技术上是一个文本文件,因为它都是 ASCII,你不想这样对待它,因为它真的是一个轻量级的数据库——如果两个人改变了它,你不能合并内容,而且差异通常没有帮助。该文件旨在由机器使用。本质上,您希望将其视为二进制文件。
回答by Ortwin Gentz
A diff is oftentimes useful at commit time to check what has been changed. So I find it useful to keep the diffing ability but just prevent merging. So I use this in my .gitattributes file:
diff 通常在提交时用于检查已更改的内容。所以我发现保持差异能力但只是防止合并很有用。所以我在我的 .gitattributes 文件中使用它:
*.pbxproj -crlf -merge
*.pbxproj -crlf -merge
On another note, has anybody tried using merge=union for pbxproj files? See: Should I merge .pbxproj files with git using merge=union?
另一方面,是否有人尝试对 pbxproj 文件使用 merge=union?请参阅:我应该使用 merge=union 将 .pbxproj 文件与 git 合并吗?
回答by Xiao
I wrote a python script named xUniqueto solve this merge conflicts problem.
我写了一个名为xUnique的 python 脚本来解决这个合并冲突问题。
This script do following things:
该脚本执行以下操作:
- replace all 24 chars
UUID
to project-wide unique 32 chars MD5 digests, and remove any unused UUIDs(usually caused by careless merge before). This would prevent duplicate UUIDs because different machines/Xcode generate different UUIDs in this file. Xcode does recognize it and the project could be opened. During this process, remove all invalid lines in project file - sort the project file. I wrote a python versionof sort-Xcode-project-file from Webkit teamwith more new features:
- support to sort
PBXFileReference
andPBXBuildFile
sections - remove duplicated files/refs
- avoid creating new file even if no changes made, this makes less commits after using this script
- support to sort
- 将所有 24 个字符替换
UUID
为项目范围内唯一的 32 个字符 MD5 摘要,并删除所有未使用的 UUID(通常由之前不小心合并引起)。这将防止重复的 UUID,因为不同的机器/Xcode 在此文件中生成不同的 UUID。Xcode 确实识别它并且可以打开该项目。在此过程中,删除项目文件中的所有无效行 - 对项目文件进行排序。我从 Webkit 团队编写了一个python 版本的sort-Xcode-project-file ,具有更多新功能:
- 支持排序
PBXFileReference
和PBXBuildFile
分区 - 删除重复的文件/参考
- 即使没有进行任何更改,也避免创建新文件,这会在使用此脚本后减少提交
- 支持排序
More details and updates of xUnique, please refer to README
更多关于 xUnique 的细节和更新,请参考README
回答by joliejuly
I faced the problem of corruption *.pbxproj
file after resolving merge conflicts manually. Or, more often, my files just 'disappeared' from the working tree after the merge. It drove me mad because we work in a team, so you can imagine how messy it can become very fast.
*.pbxproj
手动解决合并冲突后,我遇到了文件损坏的问题。或者,更常见的是,我的文件在合并后只是从工作树中“消失”了。这让我很生气,因为我们在一个团队中工作,所以你可以想象它会变得多么混乱。
So, I have tested merge=union
and it works well so far. I know that it can't help if files were deleted or renamed at the same time, but for adding new files it works as expected: there is no conflicts and files don't disappear after the merge. And it also saves quite a bit of time.
所以,我已经测试过了merge=union
,到目前为止它运行良好。我知道如果同时删除或重命名文件也无济于事,但是对于添加新文件,它按预期工作:没有冲突,合并后文件不会消失。而且它也节省了相当多的时间。
If you want to try it out, here is what I did.
如果你想尝试一下,这就是我所做的。
1) Create a global .gitattributes file. Run in terminal:
1) 创建一个全局的 .gitattributes 文件。在终端运行:
touch ~/.gitattributes
git config --global core.attributesfile ~/.gitattributes
2) This command should open it in a text editor:
2)这个命令应该在文本编辑器中打开它:
open ~/.gitattributes
3) When the file opens, add this line and save the file:
3) 当文件打开时,添加这一行并保存文件:
*.pbxproj binary merge=union
Done. Hope this will help new readers like it helped me.
完毕。希望这会帮助像它帮助我一样的新读者。