Paul Patterson
Paul Patterson

Reputation: 6928

Xcode warning when switching branches in git

I've lost more work as a result of failing to understand git than I have any other way. I'm now in the familiar position of being presented with a two-option warning from Xcode, which has come about as a result of my switching to a different branch in git (I did the switch at the command line - I don't use Xcode's built-in vc support). The last time I was here I guessed wrong and lost work. This time I'd like to understand what the two choices mean. Here's what I did:

// On branch master
$ git checkout images_sidebar

Here's what I got:

enter image description here

All I want to do is have Xcode present me with the project as it was when I last commited on the branch that I'm switching to.

Upvotes: 1

Views: 924

Answers (1)

kubilay
kubilay

Reputation: 5330

If I'm not mistaken, here's the scenario of your situation:
1. You are on the branch named branch1
2. You open the project with Xcode
3. While the project is opened, you checkout branch2

So Xcode remains branch1's .xcworkspace file but you have checked out branch2 so the .xcworkspace file on the disk has changed.

Here, Xcode detects that change and asks you to open this changed file or remain with the current (which will cause to override branch2's .xcworkspace file).

If you want to open the files of the branch you are switching to, then you should go with the Revert option.

There is one thing that I mostly realise by experiencing is that Xcode works a little bit dirty, like most of the other IDEs. So, you have to remain a well organised .gitignore file in your repository. I personally recommend to take a look at the schemes here: Git ignore file for Xcode projects

It won't actually affect your situation if you are just checking out between branches but when you merge with other branches, Xcode's specific files might get overridden as well and you should take care of that.

Upvotes: 3

Related Questions