Can't ignore UserInterfaceState.xcuserstate

XcodeGitXcode4Gitignore

Xcode Problem Overview


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?

Xcode Solutions


Solution 1 - Xcode

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 - Xcode

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

git rm --cached {YourProjectFolderName}.xcodeproj/project.xcworkspace/xcuserdata/{yourUserName}.xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"
  1. WARNING first try git clean -f -d --dry-run, otherwise you may lose uncommited changes.

Then: git clean -f -d

Solution 3 - Xcode

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 - Xcode

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 - Xcode

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

Solution 6 - Xcode

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

Solution 7 - Xcode

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

Solution 8 - Xcode

For me nothing worked, but this

add this line to your gitignore

*.xcuserdata

Solution 9 - Xcode

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.

Solution 10 - Xcode

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 :)

Solution 11 - Xcode

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.

Solution 12 - Xcode

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"

Solution 13 - Xcode

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

Solution 14 - Xcode

I think it would be better to write like this.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGarlicFriesView Question on Stackoverflow
Solution 1 - XcodemattView Answer on Stackoverflow
Solution 2 - XcodeXingView Answer on Stackoverflow
Solution 3 - XcodehardikdeviosView Answer on Stackoverflow
Solution 4 - XcodeJosh ValdiviesoView Answer on Stackoverflow
Solution 5 - XcodeLukas KalinskiView Answer on Stackoverflow
Solution 6 - XcoderilarView Answer on Stackoverflow
Solution 7 - XcodeFangmingView Answer on Stackoverflow
Solution 8 - XcodeQadir HussainView Answer on Stackoverflow
Solution 9 - XcodeMohammed Ali KhaledView Answer on Stackoverflow
Solution 10 - XcodeZoran SimicView Answer on Stackoverflow
Solution 11 - XcodeHarendra TiwariView Answer on Stackoverflow
Solution 12 - XcodeSachin NautiyalView Answer on Stackoverflow
Solution 13 - Xcodejayant rawatView Answer on Stackoverflow
Solution 14 - XcodeHanleiView Answer on Stackoverflow