Mox
Mox

Reputation: 411

Xcode and git problems after merging branch in to master

I'll try to piece what's been going of over the past few days. And note, I'm the only one working on this project. I keep track of all my issues/Todos in GitHub. I have a lot of feature branches, some stale and will never be merged up, but I keep around for reference.

It started when I tried merging develop into master. There was an odd merge conflict. I had added a new file to the project, worked on that file, then renamed that file. I made a commit to develop and pushed that to GitHub. I wouldn't have expected a merge conflict because of this but that is what happened.

I always check/preview for merge conflict in GitHub before carrying out the merge in Xcode.

In GitHub, I checked for conflicts by comparing Master <- Develop. GitHub reported there was a conflict, so I made a pull request in GitHub in order to investigate.

The conflict was in a file called PlannerNote.xcodeproj/project.pbxproj that looked something like (no longer can see the conflict):

<<<<<< Develop
3D1A5668256AC9B700AB319C /* AppearanceTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1A5667256AC9B700AB319C /* AppearanceTableViewController.swift */; };
==========
>>>>>>> Master

What's odd is that there isn't a conflicting line in the master branch. After all, this file was added as part of a new feature.

As per my usual workflow of trying to do all git actions within Xcode b/c it seems weird stuff happens if I use the git cli. So, my plan at this point was to attempt the merge via xcode and then fix the conflict in Xcode. That's what I did. I wound up in a file compare where the conflict was highlighted. What was odd is that both sides of the compare displayed the exact same code.I was given the choice to select left or right and, I believe, I selected left. As a side note, I could even tell by looking at the gui which file belong to which branch.

At any rate the conflict seemed to be reconciled and the merge went through. At this point, I'm on the master branch and I pushed to GitHub. I then made a change to master where I bumped the version number (I always do version bumps on master for whatever reason) and committed and pushed.

Now the real weirdness begins.

First, in GitHub for the master branch it seems as if my whole .gitignore file was, well, ignored. Every file within my project was added and pushed. Project generated files that don't need to be tracked, all pod files where added as well as my entire fastlane directory added and who knows what else. All of this should have been ignored. I'm using this .gitignore

GitHub sceenshot

Second, back in Xcode I tried switch back to develop and got this: can't switch to devlop

I can't remember the exact steps found on stackoverflow that seemed to solve this but it went something like, delete DerivedData and xcuserdata and also has some varient of git reset ...

I then was confronted with this which I solved by slinging various stackoverflow suggestion to the wall and seeing what stuck: enter image description here

So now I can change from master to develop. But I can't change back to 'master` when no changes have been made. I get the following warning: enter image description here

From the terminal git status shows: git status Pods/ should be ignored. Podfile.log should have been added and tracked long ago. I'm not really sure about PlannerNote.xcworkspace/

This all boils down to:

  1. I've got thousands of files in my repo and being tracked that shouldn't be. I'd like them removed.
  2. I can't change branch back to master.
  3. Every time I think I fixed something, something else breaks.

Possible solutions

  1. Manually remove all files that shouldn't be tracked.
  2. Some git wizardry that's likely beyond my comprehension of git.
  3. Delete git, delete my remote entirely and start from scratch. (But it would suck to lose my history of this project)
  4. Create a new branch from master and set that new branch to master.

In reality:

I have no idea what to do. Development is at a stand still and every time I think I'm back up and running, I stumble on something new that stops me in my tracks

Any suggestions?

Edit: Additional Info

These next 2 screen shots show the directories/differences between master and develop. Note all the folder/files added in Master. Not sure how that happened. It also makes me hesitant to update develop from master without cleaning up master first. Master branch develop branch

I've also tried the solutions found here

Upvotes: 3

Views: 1474

Answers (1)

mfaani
mfaani

Reputation: 36317

I've been in similar situations before. The best thing to do at this point is try not to spend too much time on figuring out the git issue. It's a bit hard to help this way. Your problem can't exactly be narrowed down remotely.

I'd recommend you go with this approach:

  • Check your current branch bad master or last develop commit. Go back to a stable master branch.

  • Then try to do pull request into master. See the comparison. Just go to GitHub and copy/paste manually the changes into new files or existing files. Hit ctrl+I to fix any indentation issues.

  • Just ignore the cocoapod changes because a pod install would just bring back those parts. No need to copy/past those

  • Make small commits. Make sure if you add a new file, then you commit the project file changes as well.

  • Also learn for future not now learn how to use git mergetool when you have conflicts. Make sure it's set to use Xcode's built-in merge conflict resolver ie it's set to use FileMerge. See here and here. It's a super simple tool to use. You said: "As a side note, I could even tell by looking at the gui which file belong to which branch." Left is your current branch. Right is the branch you're merging in. most common example, left is your develop branch, right is your master branch.

Upvotes: 1

Related Questions