17

I'm in the middle of a rebase and I need to fix some merge conflicts. When I open the file in XCode, I see the source control conflict markers (<<<<<<<, etc) in the file.

How can I use XCode's mergetool to resolve these conflicts in a graphical fashion? I'm looking for this screen:

enter image description here

Mike Miller
  • 3,368
  • 5
  • 36
  • 49
  • Why not just resolve the conflict directly in the text? — Also, how did you get into this situation? I'm betting you did the rebase outside of Xcode, right? – matt Feb 26 '19 at 15:56
  • 2
    Yes, I did. Should I have done it inside xcode? I don't even know how to do that... If you have merge conflicts , XCode behaves differently depending on how you got into that situation? – Mike Miller Feb 26 '19 at 17:36
  • 1
    Actually my point was just the opposite: no you shouldn't have done it inside Xcode because you can't, so you must have done it elsewhere — so why then do you want to use Xcode to resolve the conflict? For example, if you did a rebase using SourceTree, you can resolve the conflict using SourceTree — or, as I said, just directly in the text, which is often far and away the simplest approach. – matt Feb 26 '19 at 18:02
  • @MikeMiller To clarify matt's first question, in the part of your screenshot highlighted in blue, there's a switch between the two versions of the file. Click the switch to choose which version to use. In your screenshot the version on the right would be used if you clicked the Merge button. – Swift Dev Journal Feb 26 '19 at 19:39
  • @MarkSzymczyk My problem is I don't know how to get to the screen in my screenshot (I found the screenshot online somewhere). It doesn't come up when I launch the FileMerge tool as in matt's answer. That launches something else: https://imgur.com/hI82XQE. Do I have an old version of FileMerge or something? I'm running XCode 10.1... – Mike Miller Feb 27 '19 at 02:43
  • But you don't _need_ the screen in your screenshot, because FileMerge provides an equivalent graphical interface for resolving merge conflicts. – matt Feb 27 '19 at 16:41
  • 3
    @matt See my comment on your answer. It's not about *needing* a better tool, it's about knowing one is available but not knowing how to access it. Saying FileMerge is an equivalent graphical interface to imgur.com/hI82XQE is like saying TextEdit is equivalent to XCode when editing swift files. I'd like to use a code editor designed for swift files when resolving conflicts with my swift files. XCode has this functionality, I just don't know how to access it. – Mike Miller Feb 28 '19 at 14:18
  • But how can you access it when you didn't do the merge in Xcode? Your requirements make no sense. Xcode has no idea what's going on here. You are in the middle of a rebase performed completely outside of Xcode sphere of understanding. It seems to me you don't really have a question: you're just complaining that Xcode's git support is very limited. But, as I said in an early comment, we already _know_ that. – matt Feb 28 '19 at 18:51
  • 1
    So I guess that's the unfortunate answer to my question. As you've been saying, it's impossible to use that tool to solve merge conflicts during a rebase. XCode simply doesn't support the rebase flow. https://stackoverflow.com/a/8737859/1160216. Apparently the only way to launch that tool is to do a merge using XCode's UI as described on the page where I got the screenshot in the first place: https://www.raywenderlich.com/675-how-to-use-git-source-control-with-xcode-9. WBN if you could launch that tool and use it on any file with source code markers in the file, like you can with FileMerge. – Mike Miller Feb 28 '19 at 19:55

3 Answers3

24

Pulling the answer from here

# Tell system where Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

# Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff

Then, when git tells you that there is a conflict, you can run git mergetool and it will open XCode's mergetool (like in the question's screenshot) and you can work through the conflict.

Jason Lydon
  • 7,074
  • 1
  • 35
  • 43
5

The FileMerge tool is a separate application, which you can open from the Xcode menu:

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 2
    Note that if you are using an external graphical git interface such as SourceTree, you can designate FileMerge as the graphical merge tool. – matt Feb 26 '19 at 16:08
  • 1
    FileMerge doesn't look like what's in my screenshot. It looks like this: https://imgur.com/hI82XQE. I'm running XCode 10.1. Do I need to update FileMerge somehow? Is what's in my question's screenshot not FileMerge? – Mike Miller Feb 27 '19 at 02:48
  • I don't understand what you want. This is a rebase conflict done outside of Xcode so I presume you're not going to get the same screen you showed in your original screenshot. Your imgur screen shot shows a wonderful interface for resolving the merge conflict graphically. Or, as I said before, it's trivial just to do it by editing the text directly. The problem is solved. Resolve the conflict and move on. – matt Feb 27 '19 at 03:08
  • This "wonderful interface" doesn't have syntax highlighting or any of the features that makes XCode usable. It's just a vanilla text editor. I'd like to fix my merge conflicts within XCode's editor. I know it's possible to fix all the errors by hand. It's also possible to write code in TextEdit, but why would you when there are better tools to make your life easier? "what I want" is to access the tool in my question's screenshot, which will make my life easier. It exists. How can I access it? – Mike Miller Feb 28 '19 at 14:11
  • 2
    I do like your answer, though. I didn't know how to access FileMerge from XCode - thanks for sharing! Unfortunately, FileMerge is not the tool I'm looking for. – Mike Miller Feb 28 '19 at 15:05
3

I think you are mixing up Xcode version control and merge tool. You can look at git changes with:

View > Version Editor > Show Comparison View.

And it will show you a side by side of before and after commits. Doesn't help you much with Merge conflicts to my knowledge though.

If you have a tough merge conflict such as in your pbxproj file, then I recommend opening that file with visual studio.

Or maybe this?

enter image description here

enter image description here

enter image description here

enter image description here

ScottyBlades
  • 12,189
  • 5
  • 77
  • 85