如何在 Xcode 中使用 svn 合并冲突(文件 project.pbxproj)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2004135/
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
How to merge conflicts (file project.pbxproj) in Xcode use svn?
提问by vcLwei
There are two members in our team. We use Xcode's SCM (use SVN) to manger our source code files.
We all add files to our Xcode project. He has committed to SVN server. When I update, Xcode find there has conflicts in project.pbxproj
file. Then I select quit Xcode
and manually merge the conflicts. Then I start to edit my project.pbxproj
, merge our changes. Actually I don't know how Xcode manage files, I just add some text that my project.pbxproj
file did't have. When I finish, my project can't open. I guess that because the project.pbxproj
file can't be edit by manual.
我们团队有两个成员。我们使用 Xcode 的 SCM(使用 SVN)来管理我们的源代码文件。
我们都将文件添加到我们的 Xcode 项目中。他已经致力于SVN服务器。当我更新时,Xcode 发现project.pbxproj
文件中存在冲突。然后我选择退出Xcode
并手动合并冲突。然后我开始编辑我的project.pbxproj
,合并我们的更改。实际上我不知道 Xcode 如何管理文件,我只是添加了一些我的project.pbxproj
文件没有的文本。完成后,我的项目无法打开。我猜是因为该project.pbxproj
文件无法手动编辑。
So, I want to know, when you find this problem, the project.pbxproj file have conflicts, how to solve it?
所以,我想知道,当你发现这个问题时,project.pbxproj文件有冲突,如何解决?
Thank you!
谢谢!
采纳答案by Barry Wark
Unfortunately, there's not much you can do except to make the changes manually in one check out and then check-in the newly "merged" project.
不幸的是,除了在一次签出中手动进行更改然后签入新“合并”的项目之外,您无能为力。
回答by Kendall Helmstetter Gelner
I use git but we see the same issue - if two people add files there's a merge conflict.
我使用 git 但我们看到了同样的问题 - 如果两个人添加文件,则会出现合并冲突。
Usually the editing is very easy though. Simply go into the project.pbxproj file with a text editor, and look for the merge conflict section - usually this is marked by something like :
不过,通常编辑很容易。只需使用文本编辑器进入 project.pbxproj 文件,然后查找合并冲突部分 - 通常用以下内容标记:
>>>>>>>
Stuff 1
======
Stuff 2
<<<<<<<<
In 99% of Xcode project merge conflict cases, you simply want to accept both sides of the merge (because two people added different files) - so you would simply delete the merge markers, in the above case that would end up like:
在 99% 的 Xcode 项目合并冲突情况下,您只想接受合并的双方(因为两个人添加了不同的文件)-因此您只需删除合并标记,在上述情况下,最终会像:
Stuff 1
Stuff 2
Like I said, this works great in MOST cases. If Xcode will not read the project file when you are done, just take the most recent un-merged version and manually add your files again.
就像我说的,这在大多数情况下都很有效。如果完成后 Xcode 不会读取项目文件,只需使用最新的未合并版本并再次手动添加文件。
回答by mmilleruva
This solution is only for git, but you can add a .gitattributes
file to your project then within that file add the following line:
此解决方案仅适用于 git,但您可以将.gitattributes
文件添加到项目中,然后在该文件中添加以下行:
*.pbxproj merge=union
*.pbxproj merge=union
This will tell git to keep both sides of the merge which will be what you want the vast majority of the time.
这将告诉 git 保留合并的双方,这在大多数情况下都是您想要的。
回答by Manuel
To manually solve the merge conflicts, check the UUID
of each conflicting item.
要手动解决合并冲突,请检查UUID
每个冲突项的 。
Example:
例子:
<<<<<<< HEAD
6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
3F01C4B72008E70000889299 /* NewFileA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F01C4B72008E70000889299 /* NewFileA.swift */; };
=======
6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
4DF01C4B72008E70000882ED /* NewFileB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF01C4B72008E70000882ED /* NewFileB.swift */; };
>>>>>>> branch_to_merge
Check each UUID:
检查每个 UUID:
- If it occurs in both versions, remove it in one version:
ExistingFile.swift
- If it does not occur on the comparing branch, keep it:
NewFileA.swift
andNewFileB.swift
- If it is not referenced anywhere else in the file, i.e. you can only find one occurrence in the whole
project.pbxproj
file, I would assume it is an artefact and safe to delete it.
- 如果在两个版本中都出现,请在一个版本中将其删除:
ExistingFile.swift
- 如果它没有出现在比较分支上,保持它:
NewFileA.swift
和NewFileB.swift
- 如果文件中的其他任何地方都没有引用它,即您只能在整个
project.pbxproj
文件中找到一次,我会认为它是人工制品并且可以安全地删除它。
The result would be:
结果将是:
6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
3F01C4B72008E70000889299 /* NewFileA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F01C4B72008E70000889299 /* NewFileA.swift */; };
4DF01C4B72008E70000882ED /* NewFileB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF01C4B72008E70000882ED /* NewFileB.swift */; };
Note:I don't recommend adding *.pbxproj merge=union
to the .gitattribues
file to basically ignore merge conflicts because a conflicting merge should alway be checked manually unless there is a sophisticated script doing that for you.
注意:我不建议添加*.pbxproj merge=union
到.gitattribues
文件以基本上忽略合并冲突,因为除非有复杂的脚本为您执行此操作,否则应始终手动检查冲突合并。
回答by G. Shearer
I was looking for a straightforward solution to this problem when I came across this other question/answer:
当我遇到另一个问题/答案时,我正在寻找解决这个问题的直接方法:
https://stackoverflow.com/a/14180388/307217
https://stackoverflow.com/a/14180388/307217
I was completely blown away by how simple this solution is, I was trying to merge in a disparate feature branch which was almost 200 revisions behind the trunk, XCode and Mercurial were not being happy campers about it. I tried manually merging the pbxproj file (which had over 100 conflicts) 8 times before trying this solution.
我完全被这个解决方案的简单震惊了,我试图合并一个不同的功能分支,这个分支在主干后面几乎有 200 个修订版,XCode 和 Mercurial 对此并不满意。在尝试此解决方案之前,我尝试手动合并 pbxproj 文件(有超过 100 个冲突)8 次。
Basically the solution is as such (assuming you use Mercurial, because it's awesome):
基本上解决方案是这样的(假设您使用 Mercurial,因为它很棒):
Attempt your merge in mercurial:
hg update FEATURE_BRANCH hg merge default *mercurial gives you a ton of crap about the pbxproj file having merge conflicts*
Open Xcode
- From the top toolbar, select Xcode->Open Developer Tool->FileMerge
- On the left, open your conflicted 'project.pbxproj' file (the one with merge conflict markup in it)
- On the right side, open your 'project.pbxproj.orig'
- Select File->Save Merge and save over the 'project.pbxproj' file
Then back at the command line:
hg resolve -m ProjectName.xcodeproj/project.pbxproj *merge any other broken files* hg commit -m "manually merged with trunk"
- Eat Cake Because You Are Done
尝试在 mercurial 中合并:
hg update FEATURE_BRANCH hg merge default *mercurial gives you a ton of crap about the pbxproj file having merge conflicts*
打开 Xcode
- 从顶部工具栏中,选择 Xcode->Open Developer Tool->FileMerge
- 在左侧,打开冲突的“project.pbxproj”文件(其中包含合并冲突标记的文件)
- 在右侧,打开您的“project.pbxproj.orig”
- 选择 File->Save Merge 并保存“project.pbxproj”文件
然后回到命令行:
hg resolve -m ProjectName.xcodeproj/project.pbxproj *merge any other broken files* hg commit -m "manually merged with trunk"
- 吃蛋糕,因为你已经完成了
回答by tommys
As stated above the most common wayof handling the conflicts is to
如上所述,处理冲突的最常见方法是
- accept "everything"
- re-import the files into the project
- 接受“一切”
- 将文件重新导入到项目中
I Wrote a bash-scriptthat takes care of (1) above.
我写了一个bash 脚本来处理上面的 (1)。
Note that this will only solve the most common case of merge conflicts!
请注意,这只会解决最常见的合并冲突情况!
#!/bin/bash
#
#
#
if [ $# -eq 0 ]
then
echo "File must be provided as argument, darnit!"
exit 1
fi
if [ $# -eq 2 ]
then
echo "only ONE File must be provided as argument, darnit!"
exit 1
fi
echo "Will remove lines from file:"
grep -v "<<<<<" | grep -v ">>>>>>" | grep -v "====" > out.tmp;mv out.tmp
echo "Done removing lines from file:"
回答by realbusyman
Sometimes one or few files could be recreated (for example ManagedObjects) in different branches, so when you'll merge there may be two declarations for one file in one block. In this case you should delete one of the declarations.
有时可能会在不同的分支中重新创建一个或几个文件(例如 ManagedObjects),因此当您合并时,一个块中的一个文件可能会有两个声明。在这种情况下,您应该删除其中一个声明。
回答by qinmu2127
I happened to encounter this tricky problem.
我碰巧遇到了这个棘手的问题。
Instead of manually dealing with these conflicts, you can try this.
Suppose you are on feature branch.
你可以试试这个,而不是手动处理这些冲突。
假设您在功能分支上。
- Git checkout master.
- Copy content in
project.pbxproj
- Git checkout to your feature branch, and paste it.(Override the current content in
project.pbxproj
) Run
react-native link
- Git结帐大师。
- 复制内容
project.pbxproj
- Git checkout 到您的功能分支,然后粘贴它。(覆盖 中的当前内容
project.pbxproj
) 跑
react-native link
回答by Guilherme Vallone
You can open it on VSCODE and fix the conflicting merge there. look for some colored annotations on the IDE or look for <<< >>> in the text search.
您可以在 VSCODE 上打开它并在那里修复冲突的合并。在 IDE 上查找一些彩色注释或在文本搜索中查找 <<< >>>。
回答by Ali Ers?z
So far the best visual merge tool I have used for pbx files is Visual Studio Code's merge tool. I open the pbx file in Code app and fix conflicts then open XCode again.
到目前为止,我用于 pbx 文件的最好的可视化合并工具是 Visual Studio Code 的合并工具。我在 Code 应用程序中打开 pbx 文件并修复冲突,然后再次打开 XCode。