Can't ignore UserInterfaceState.xcuserstate

126,355

Solution 1

Git is probably already tracking the file.

From the gitignore docs:

To stop tracking a file that is currently tracked, use git rm --cached.

Use this, replacing [project] and [username] with your info:

git rm --cached [project].xcodeproj/project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"

Alternatively you can use the -a option to git commit that will add all files that have been modified or deleted.

Once you've removed the file from git, it will respect your .gitignore.

Solution 2

In case that the ignored file kept showing up in the untracked list, you may use git clean -f -d to clear things up.

1.

git rm --cached {YourProjectFolderName}.xcodeproj/project.xcworkspace/xcuserdata/{yourUserName}.xcuserdatad/UserInterfaceState.xcuserstate

2.

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

3. WARNING first try git clean -f -d --dry-run, otherwise you may lose uncommited changes.

Then: git clean -f -d

Solution 3

All Answer is great but here is the one will remove for every user if you work in different Mac (Home and office)

git rm --cache */UserInterfaceState.xcuserstate
git commit -m "Never see you again, UserInterfaceState"

Solution 4

Had a friend show me this amazing site https://www.gitignore.io/. Enter the IDE of your choice or other options and it will automatically generate a gitignore file consisting of useful ignores, one of which is the xcuserstate. You can preview the gitignore file before downloading.

Solution 5

In case the file keeps showing up even after doing everything mentioned here, make sure that this checkbox in Xcode settings is unchecked:

enter image description here

Share:
126,355
GarlicFries
Author by

GarlicFries

Jack of all trades...master of none.

Updated on July 31, 2022

Comments

  • GarlicFries
    GarlicFries almost 2 years

    I'm using Git for Xcode 4 project version control. I've explicitly added ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate to .gitignore, but Git it won't ignore it. Any ideas why this is so?

  • Rob Caraway
    Rob Caraway over 11 years
    I have this problem but when I try to remove the xcuserstate file it says 'did not match any files'. Whats going on?
  • MaxGabriel
    MaxGabriel almost 11 years
    I have the same problem as @RobCaraway
  • Brainware
    Brainware almost 11 years
    This helped me: 1) quit xcode; 2) go to the project directory and do an "ls -la" from the terminal app to make sure you see the .git and .gitignore files; 3) change "ProjectFolder" in the example above to the name of your project; 4) do the two git commands that matt shows; 5) Relaunch XCode and do a commit and verify that the xcuserstate file is no longer listed.
  • bpn
    bpn about 10 years
    Any idea how to do the equivalent in svn? I am getting the same issue, wherein svn is not ignoring the file
  • Jay Versluis
    Jay Versluis about 10 years
    Thank you @Brainware!! It finally worked thanks to your suggestion. I think closing Xcode beforehand is very important.
  • cspam
    cspam about 9 years
    github now gives you a default .gitignore file that includes this file among others but you still have to go through your steps. kind of annoying
  • trdavidson
    trdavidson almost 9 years
    @matt just went through these steps but still have the same isse..also tried the commit -a option with no luck. Any suggestions?
  • Jeremy Luisetti
    Jeremy Luisetti over 8 years
    Thanks men, git clean -f -d just deleted . xcodeproj and other files from my project...
  • zero0cool
    zero0cool about 6 years
    It's strongly advised to use the --dry-run flag before running git clean, i.e. git clean -f -d --dry-run to see what happens
  • MEnnabah
    MEnnabah almost 6 years
    Is it possible to make the [username] variables based on the machine? It would be helpful when working with a team!
  • Bhavin_m
    Bhavin_m about 5 years
    Please help for the SVN subversion for the same.
  • allenlinli
    allenlinli about 5 years
    What does git clean -f -d do?
  • kalafun
    kalafun about 5 years
    Don't use the git clean -f -d if you have uncommitted files changes! I used it and it removed my freshly created files with content already created! :) So first commit and then clean
  • Manish
    Manish almost 5 years
    @All those who have issue of 'did not match any files', you can go to .xcodeproj show packages, then you can see xcuserdata, you can delete from there. and then commit.
  • Felecia Genet
    Felecia Genet over 3 years
    I also was getting did not match any files. For whatever reason I had to use the full path: /Users/[USERNAME AS SEEN IN TERMINAL]/Desktop/[MY DEV PROJECTS FOLDER]/[MY XCODE PROJECT FOLDER]/[MY PROJECT NAME].xcworkspace/xcuserdata/[USERNAME AS SEEN IN TERMINAL].xcuserdatad/UserInterfaceState.xcuserstate