[xcode] Can't ignore UserInterfaceState.xcuserstate

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?

This question is related to xcode git xcode4 gitignore

The answer is


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.


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.


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"

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


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


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


I think it would be better to write like this.

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


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


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


For me nothing worked, but this

add this line to your gitignore

*.xcuserdata

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"

Examples related to xcode

Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 iPhone is not available. Please reconnect the device Make a VStack fill the width of the screen in SwiftUI error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65 The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Xcode 10: A valid provisioning profile for this executable was not found Xcode 10, Command CodeSign failed with a nonzero exit code

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to xcode4

How to select Multiple images from UIImagePickerController Xcode: failed to get the task for process Adding Image to xCode by dragging it from File The identity used to sign the executable is no longer valid Can't ignore UserInterfaceState.xcuserstate Why can I not switch branches? How to Empty Caches and Clean All Targets Xcode 4 and later Apple Mach-O Linker Error when compiling for device How can I build for release/distribution on the Xcode 4? Xcode 4 - "Archive" is greyed out?

Examples related to gitignore

Gitignore not working How to add files/folders to .gitignore in IntelliJ IDEA? Apply .gitignore on an existing repository already tracking large number of files Ignore .classpath and .project from Git .gitignore all the .DS_Store files in every folder and subfolder Correctly ignore all files recursively under a specific folder except for a specific file type What should be in my .gitignore for an Android Studio project? Commit empty folder structure (with git) How to remove files that are listed in the .gitignore but still on the repository? What to gitignore from the .idea folder?