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?
14 Answers
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
.
-
5I 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
-
31This 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. Commented Aug 14, 2013 at 22:38
-
1Any idea how to do the equivalent in svn? I am getting the same issue, wherein svn is not ignoring the file– bpnCommented 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.– ManishCommented Jun 13, 2019 at 6:00
-
1I 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
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
-
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– cspamCommented Feb 19, 2015 at 22:40
-
3Thanks men, git clean -f -d just deleted . xcodeproj and other files from my project... Commented Oct 5, 2015 at 12:17
-
1It'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 Commented Mar 23, 2018 at 6:26 -
-
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– kalafunCommented May 7, 2019 at 9:02
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"
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.
In case the file keeps showing up even after doing everything mentioned here, make sure that this checkbox in Xcode settings is unchecked:
Here are some demo & short cuts if you uses GitHub, the basic ideas are the same.
1. Open terminal like this
2. Paste the below command to terminal followed by a space and then paste the path of the .xcuserstate file simply like this
3. Make sure you have the correct git ignore and then commit the code :)
This works for me
Open the folder which contains the project file
project.xcworkspace
from the terminal.Write this command:
git rm --cached *xcuserstate
This will remove the file.
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.
- again right-click on the same file and you will notice ignore option is now enabled then click on ignore button.
- 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.
-
-
Thanks! This is NOT a temp solution, this is a solid GUI solution just the same as the accepted solution in Terminal– rommexCommented Mar 21, 2023 at 13:56
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 :)
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.
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"
I think it would be better to write like this.
git rm --cache *//UserInterfaceState.xcuserstate**