简体   繁体   中英

Xcode: Added file in GIT sub-branch, now attempts to merge upward give, “Tree Conflict”

I'm only using a local repository with Xcode 8.2.1. It's a one-man show, I'm the only one making code changes. Over the years, I created a series of sub-branches in GIT as follows:

master
     branch1
     ...
     branch14
            branch14.1
            ...
            branch 14.13    //added lots of new code/classes
                   branch 14.13.NewCombatReports //refactor 1 class into 2

In 14.13 I added quite a few new classes by using xcode's "New File" option and creating new classes. Once I had things functional, I created a sub branch, 14.13.NewCombatReports, to isolate refactoring one of the larger classes (separating a large chunk of code into it's own, new class, BattleManager.m/h).

When I was satisfied, I committed the changes, then attempted to merge into the parent branch. I received an error saying:

The operation could not be performed because of one or more tree conflicts. The files BattleManagerClass.h and BattleManagerClass.m had a tree conflict

Following the advice of similar SO questions, I ran git status in the same directory where BattleManager* resides, which returned:

On branch master.DevMain.14.13.newCombatReports
Untracked files:
    (use "git add <file>..." to include in what will be committed)

        ../CloudKitHelperClass (xxxxxxxx's conflicted copy 2016-11-18).m
        ../yyyyyy.xcodeproj/project.xcworkspace/xcuserdata/thunk.xcuserdatad/.gitignore
        ../yyyyyy.xcodeproj/project.xcworkspace/xcuserdata/thunk.xcuserdatad/UserInterfaceState (xxxxxxxx's conflicted copy 2016-11-18).xcuserstate
        ../yyyyyy.xcodeproj/xcuserdata/thunk.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

nothing added to commit but untracked files present (use "git add" to track)

None of which seem related to the new BattleManager class. After plodding around, not really understanding what I'm doing in GIT, I eventually removed the class from the xcode project and moved the BattleManager files off to ~/tmp. I committed the change and then successfully merged the rest of the changes in 14.13.NewCombatReports back in to 14.13. At that point, I re-added the new BattleManager class back into 14.13 and rebuilt. All was well, or so I thought.

When I subsequently tried to merge 14.13 into 14, I got a TON of tree conflicts, complaining about every single class file I had added in 14.13.

So I have apparently done something fundamentally wrong, such that GIT doesn't like it when I try to merge branches upward that contain net new files. I don't know the workings of GIT very well and don't understand:

  1. What is a "tree conflict" error trying to tell me me in the context of a local repository? I don't understand what my current revision is conflicting with.
  2. how do I fix it so I can merge upwards this branch containing new files?

This question seems very similar Xcode merge branch,remind tree conflict when add some new file . The comments link to: The operation could not be performed because "PROJECTNAME" has one or more tree conflicts which talks about trying to reconcile directory structures between the local and server versions. Since I'm not dealing with a server, I don't understand how to apply that advice.

I've seen similar weird failures with xcode attempting git operations.

Just closing the project, exiting xcode and rebooting has cleared some issues for me.

Using one of gui git tools sometimes help, too. There are several different options, but I use gitbox and is available from the app store. It has an option to force a merge, which might solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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