[英]Xcode Project file git merge conflict
In Xcode, what's the best way to avoid Git conflict in the project file?在Xcode中,工程文件中避免Git冲突的最佳方法是什么? (I am in manual git, not using Xcode interface for git) (我在manual git,不是用git的Xcode接口)
I've cloned mapbox-ios-sdk from Github, hacked it, and now the remote master has changed.我从 Github 克隆了 mapbox-ios-sdk,破解了它,现在远程主机已经改变了。 When I tried to pull the remote changes into my local, after merging there would be merge conflict in the project file.当我试图将远程更改拉到我的本地时,合并后项目文件中会出现合并冲突。 (Specifically, I mean the project.pbxproj in the.xcodeproj) (具体来说,我指的是.xcodeproj中的project.pbxproj)
I do not really think project file should be put into the ignore, since if there are any new files the project file, the.pbxproj file seems to be changed.我真的不认为应该忽略项目文件,因为如果项目文件有任何新文件,.pbxproj 文件似乎已更改。 (Or am I just plain wrong and this file should be put to ignore? But obviously it wasn't on ignored in the mapbox-ios-sdk to begin with. People need the project file after all.) But I've also ran into this conflict before in my collaboration project with another collaborator and it's keeping me from using Git altogether. (或者我完全错了,这个文件应该被忽略?但显然它并没有在 mapbox-ios-sdk 中被忽略。毕竟人们需要项目文件。)但我也跑了在我与另一个合作者的合作项目之前就陷入了这场冲突,这让我无法完全使用 Git。
Should I figure out how to manually resolve conflict or is there a better way to deal with this?我应该弄清楚如何手动解决冲突还是有更好的方法来处理这个问题?
.pbxproj will change when you add new files to the project. .pbxproj 将在您向项目添加新文件时更改。 There will be conflicts if two or more collaborators add files at the same time (without getting one another's changes first).如果两个或多个协作者同时添加文件(而不先获取彼此的更改),则会发生冲突。 We are avoiding this in my project by following these steps before and after adding new files:我们在我的项目中通过在添加新文件之前和之后执行以下步骤来避免这种情况:
It's wimpy, but we don't relish manually resolving .pbxproj conflicts.它很弱,但我们不喜欢手动解决 .pbxproj 冲突。
Also, see this Stack Overflow question with excellent responses: How to use Git properly with XCode?另外,请参阅此堆栈溢出问题,并给出了很好的回答: How to use Git correct with XCode?
A lot of websites simply suggest to use a .gitattributes file with:许多网站只是建议使用 .gitattributes 文件:
*.pbxproj merge=union
We're gonna try this approach before trying to use scripts.在尝试使用脚本之前,我们将尝试这种方法。 If we find any issues I'll be sure to update this post.如果我们发现任何问题,我一定会更新这篇文章。 Also if anyone else has comments to this approach please include.此外,如果其他人对此方法有意见,请包括在内。
You should check my script xUnique , it is now the best solution to merge Xcode project file before Apple takes action on it.您应该检查我的脚本xUnique ,它现在是在 Apple 对其采取行动之前合并 Xcode 项目文件的最佳解决方案。
project.pbxproj
to JSON format将project.pbxproj
转换为 JSON 格式objects
in JSON and give every UUID an absolute path, and create a new UUID using MD5 hex digest of the path迭代 JSON 中的所有objects
并给每个 UUID 一个绝对路径,并使用路径的 MD5 十六进制摘要创建一个新的 UUID
children
, files
, PBXFileReference
and PBXBuildFile
list and remove all duplicated entries in these lists对包含children
、 files
、 PBXFileReference
和PBXBuildFile
列表的项目文件进行排序,并删除这些列表中的所有重复条目
sort_pbxproj
method in xUnique.py if you want to know the implementation;如果您想了解实现,请参阅sort_pbxproj
方法;sort-Xcode-project-file
, with some differences in ordering PBXFileReference
and PBXBuildFile
它是从我修改后的sort-Xcode-project-file
移植而来的,在PBXFileReference
和PBXBuildFile
排序上有一些差异In most case, you can fix the merge by following code, remove the lines which git adds:在大多数情况下,您可以通过以下代码修复合并,删除 git 添加的行:
#!/bin/bash
FILE={PRODUCT_NAME}.xcodeproj/project.pbxproj
sed '/======/d' $FILE | sed '/<<<<</d' | sed '/>>>>>/d' > temp
cat temp > $FILE
rm temp
but if you rename the group of your project and it leads to conflicts, you will manually delete the extra lines of your original group.但是如果你重命名你的项目的组,导致冲突,你将手动删除原来组的多余行。
When this is caused by adding files from two or more collaborators/branches (which in my experience has always been the case to date and can be checked by looking at the diff) I do this:当这是由于添加来自两个或多个合作者/分支的文件(根据我的经验,迄今为止一直如此,可以通过查看差异来检查)引起的,我这样做:
(I am not convinced step 2 is really necessary - but feels neater to me). (我不相信第 2 步真的有必要——但对我来说感觉更整洁)。
You can also use Mergepbx manually do it as follows您也可以使用 Mergepbx 手动执行如下操作
I need to get master code in my branch So, I was taking pull from master and I have changed in my .pbxproj file and master has different configuration.So, It was showing conflict in .pbxproj file.我需要在我的分支中获取 master 代码所以,我从 master 那里拉取,并且我在我的 .pbxproj 文件中进行了更改,并且 master 具有不同的配置。所以,它在 .pbxproj 文件中显示冲突。 Follow these steps to resolve it请按照以下步骤解决它
Open .pbxproj in Finder -> Right click on file Choose Show Package Contents -> Choose .在 Finder 中打开.pbxproj ->右键单击文件选择Show Package Contents -> 选择 。 pbxproj file and open it with TextEdit- > It will show conflict lines as below. pbxproj 文件并使用 TextEdit- >打开它,它将显示如下冲突行。
<<<<<<< HEAD"
// head changes
===========
// Your changes
>>>>>>>>
You have choose the right one from head Changes and your changes and Delete the rest.您已经从 head Changes 和您的更改中选择了正确的一个,然后删除其余的。 Now commit you code现在提交你的代码
git add .
git commit -m"conflict resolved"
git status // Check you files status
If everything is fine the push you code.如果一切正常,则推送您的代码。
git push
If all else fails, while tedious.如果一切都失败了,虽然乏味。 you can open your pbxproj in your git client, then manually, go file by file and ensure each one is either removed or has 4 lines (6 occurrences).您可以在 git 客户端中打开 pbxproj,然后逐个文件手动打开 go 并确保每个文件都被删除或有 4 行(出现 6 次)。
I had the same problem, so I wrote a tool in Swift that will resolve conflicts due to adding, deleting, moving, and renaming files and groups.我也遇到了同样的问题,于是在Swift写了一个工具,可以解决文件和组的增删改名冲突。 You can set it up as a git merge driver so the script runs automatically when you merge a branch.您可以将其设置为 git 合并驱动程序,以便脚本在您合并分支时自动运行。
You can check it out here: XcodeMergeDriver你可以在这里查看: XcodeMergeDriver
I made an app for fixing things in Xcode project files when these sort of things go wrong.我制作了一个应用程序,用于在出现此类问题时修复 Xcode 项目文件中的内容。 You'd still have to do some manually merging first though, unfortunately.不幸的是,您仍然必须先进行一些手动合并。 https://itunes.apple.com/us/app/xsaviour/id1449886415?mt=12 https://itunes.apple.com/us/app/xsaviour/id1449886415?mt=12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.