36

In Xcode 5.0.2, I try to pull from a remote and am given the following message:

"The working copy 'project-name' has uncommitted changes. Commit or discard the changes and try again."

Fair enough. I pull up the commit dialog, and am then given the message, "This file does not exist at the requested revision." Clicking 'OK' brings me on into the commit dialog. (There is no revision displayed in the right pane, presumably for the same reason I was given the most recent message.) Selecting the flat view, I see that there is only one modified file: project.pbxproj. I enter a commit message and click 'Commit 1 File'. When I then go to pull, I find that I am in exactly the same position as before--the same messages appear and I am unable to pull (or push) no matter how many times I make a commit.

Curious, I run git diff to see just what has changed. Nothing. git status provides me with equally helpful output: nothing to commit, working directory clean. git push or git pull? Yep, those work just fine from the command line.

So what gives? Why does Xcode insist that I have changes in my working directory? Why won't it tell me what they are? Have tried restarting Xcode and system. While I'm happy that I still have some way to push and pull, it would be really nice if the Xcode git integration was behaving nicely. Any ideas?

I've found these similar questions, but none address this particular issue (or provide an acceptable solution):

4
  • 2
    Would a git reset --hard help? (if you don't have any private file in your working tree)
    – VonC
    Jan 7, 2014 at 14:25
  • 1
    Makes no difference, @VonC. Jan 7, 2014 at 15:43
  • I'm suffering with this exact same problem on Xcode 5 too. I wish there was a way to resolve this. I need to switch back to a local branch to continue development. Jan 15, 2014 at 11:26
  • Try the -f flag for "force", for example git checkout -f master Jun 15, 2022 at 7:25

6 Answers 6

76

Okay, so I fixed my issue.

With Xcode open:

  1. Open terminal - cd / to your project directory.
  2. Type in: "git reset --hard"
  3. Type in git status

Restart Xcode and make a commit (Just a comment or something )

Repeat the above steps.

This sorted out my issue for me.

4
  • Thanks, @Tander. As suggested up in the comments on the question, however, that doesn't fix my problem... Jan 15, 2014 at 15:11
  • 2
    In my case, the "git reset --hard" step was sufficient to fix the issue. Thank you @Tander
    – Kqtr
    Sep 14, 2018 at 11:28
  • 6
    No problem @Kqtr - surprisingly, 4 years later and this is still and issue in the latest version of Xcode. Sep 14, 2018 at 15:39
  • Every time I clicked something in Xcode it changed my userdata file, so I had to git reset --hard after every move to the unstashing action. In hindsight, maybe I only needed to do the reset right before unstashing, but for everyone else's awareness, changing views in Xcode or clicking on UI will refresh your IDE and update your userdata file. May 23, 2020 at 18:10
8

You must fix it with command line git. Go to your working folder in Terminal, type:

git status

That will show you what files have uncommitted changes. Crashlytics, for instance, will update itself as soon as you run it, and even using Xcode/Source Control/Discard Changes won't get rid of it.

Once you see the files that have uncommitted changes (ignore added files), use:

git checkout -- Folder/filename.ext

That's the same as a "discard" in Xcode.

After you've done that, go back to Xcode and you should be able to switch branches.

3

xCode is really-really crappy. Everytime you just look at files, a file called UserInterfaceState.xcuserstate is changed. You don't see it in the overview of xCode itself, through the command line you can.

Quick fix:

  1. Open Terminal
  2. CD to your project directory, and type the following:
  3. git add .
  4. git commit -m "Commit"
  5. git push origin master
2
  • How can we exclude the file?
    – JCutting8
    Jan 24, 2022 at 7:20
  • @JCutting8 Idk, i should not recommend it, maybe your UI is gone than
    – J. Doe
    Jan 24, 2022 at 20:50
0

App Code solution:

  1. Confirm git status in Terminal:

    git status

  2. Open 'yourProject.xcworkspace' in App Code

  3. VCS > Git > Branches...

  4. Remote Branches > yourBranch > Checkout as new local branch

  5. Confirm fix via Terminal:

    git status

0

Try this:

Step 1:

git rm --cached ProjectName.xcodeproj/project.xcworkspace/xcuserdata/username.xcuserdatad/UserInterfaceState.xcuserstate

Step 2:

git commit -m "Removed file that shouldn't be tracked"
0

The top answer did not work for me unfortunately because I had untracked git files.

To fix this, go to your working folder in Terminal, type: git status

That will show you files that are not being tracked by git. Now add each file with:

git add <file with location>

You should be able to copy/pasta the file with location from what gets printed out from git status.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.