380

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?

0

14 Answers 14

805

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.

10
  • 5
    I have this problem but when I try to remove the xcuserstate file it says 'did not match any files'. Whats going on? Commented Nov 7, 2012 at 2:04
  • 31
    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.
    – Brainware
    Commented Aug 14, 2013 at 22:38
  • 1
    Any idea how to do the equivalent in svn? I am getting the same issue, wherein svn is not ignoring the file
    – bpn
    Commented Mar 4, 2014 at 19:59
  • 1
    @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.
    – Manish
    Commented Jun 13, 2019 at 6:00
  • 1
    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 Commented Jan 19, 2021 at 21:11
66

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

5
  • 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
    – cspam
    Commented Feb 19, 2015 at 22:40
  • 3
    Thanks men, git clean -f -d just deleted . xcodeproj and other files from my project... Commented Oct 5, 2015 at 12:17
  • 1
    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
    – zero0cool
    Commented Mar 23, 2018 at 6:26
  • What does git clean -f -d do?
    – allenlinli
    Commented Apr 3, 2019 at 6:37
  • 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
    – kalafun
    Commented May 7, 2019 at 9:02
55

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"
0
25

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.

0
21

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

1
  • it is not working
    – yasin89
    Commented Nov 25, 2022 at 8:46
14

Just "git clean -f -d" worked for me!

13

Here are some demo & short cuts if you uses GitHub, the basic ideas are the same.

1. Open terminal like this

enter image description here

2. Paste the below command to terminal followed by a space and then paste the path of the .xcuserstate file simply like this

git rm --cached enter image description here

3. Make sure you have the correct git ignore and then commit the code :)

enter image description here

7

This works for me

  1. Open the folder which contains the project file project.xcworkspace from the terminal.

  2. Write this command: git rm --cached *xcuserstate

This will remove the file.

7

Here is one more simple solution if you are using the source tree app. here are the instructions

1.Right-click on the file which you want to add to the git ignore list and select stop tracking. enter image description here

  1. again right-click on the same file and you will notice ignore option is now enabled then click on ignore button.

enter image description here

  1. now you can reset or commit your changes for the same file it depends on whether your changes are important or not. changes in the future will not be tracked for the selected file.
2
  • This is temporary solution but is solve thanks
    – yasin89
    Commented Nov 25, 2022 at 8:49
  • Thanks! This is NOT a temp solution, this is a solid GUI solution just the same as the accepted solution in Terminal
    – rommex
    Commented Mar 21, 2023 at 13:56
5

For me nothing worked, but this

add this line to your gitignore

*.xcuserdata
4

Here is a very nice explanation of how to remove the files in question recursively from your git history: http://help.github.com/remove-sensitive-data/

Very useful, because otherwise tools tend to 'hang' while trying to show the diff on those huge files that shouldn't have been checked in the first place...

Here's what you can do (in short) to get rid of the largest stuff:

cd YourProject
git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r YourProject.xcodeproj/project.xcworkspace' HEAD
# see what you want to do with your remote here...
# you can: git push origin master --force
# or you can delete it and push a fresh new one from your cleaned-up local...
rm -rf .git/refs/original
git gc --prune=now
git gc --aggressive --prune=now

Worked very nicely for me :)

2

You can also ignore files from Xcode preferences itself.

Generate gitignore file from https://www.toptal.com/developers/gitignore

Go to Xcode -> Preferences -> Source Control -> Git -> Add all ignore items in the list...Even though UI is not really useful & you have to add all items individually but adding ignore files here surely works.

enter image description here

enter image description here

enter image description here

1
  • This solution worked for me in Xcode 14.2. Thank you!
    – Hollycene
    Commented Apr 15, 2023 at 16:33
0

For xcode 8.3.3 I just checked tried the above code and observe that, now in this casewe have to change the commands to like this

first you can create a .gitignore file by using

 touch .gitignore

after that you can delete all the userInterface file by using this command and by using this command it will respect your .gitignore file.

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

I think it would be better to write like this.

git rm --cache *//UserInterfaceState.xcuserstate**

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.