46

I'm working in a Xcode project, and I'm trying to configure the .gitignore to not get anything inside the xcuserdata folder.

I have the following .gitignore:

# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
xcuserdata/*

but every time that I build/run the project and execute git status, it still shows the following midified file:

modified: MyProject.xcodeproj/project.xcworkspace/xcuserdata/fernando.xcuserdatad/UserInterfaceState.xcuserstate

Does anybody have any idea what's wrong?

jscs
  • 63,694
  • 13
  • 151
  • 195
Fernando
  • 1,323
  • 2
  • 12
  • 17
  • Does this answer your question? [Can't ignore UserInterfaceState.xcuserstate](https://stackoverflow.com/questions/6564257/cant-ignore-userinterfacestate-xcuserstate) – Alex Cohn Sep 27 '20 at 09:07

12 Answers12

52

I found the solution

the problem was not in the .gitignore file

the problem was the UserInterfaceState.xcuserstate that was not removed from git server, found the solution in the following link:

Can't ignore UserInterfaceState.xcuserstate

Community
  • 1
  • 1
Fernando
  • 1,323
  • 2
  • 12
  • 17
  • 1
    Just run this for any file that was previously saved or staged that you want to get ignored `git rm --cached FILE_TO_REMOVE` as cached files will bypass .gitignore configs – eNeF Sep 11 '22 at 06:31
13

Additional info

I have also encountered this and seems not to work since .gitignore still adding them after committing. What I have added does the charm for me

.... this can't be read by the .gitignore:

xcuserdata/*

adding this works for me:

*xcworkspace/xcuserdata/*

or to be read:

*/xcuserdata/*
14wml
  • 4,048
  • 11
  • 49
  • 97
eNeF
  • 3,241
  • 2
  • 18
  • 41
10

On top of adding *.xcuserstate to your .gitignore file, remember to remove your cached *.xcuserstate

git rm --cached [YourProjectName].xcodeproj/project.xcworkspace/xcuserdata/[ YourUsername].xcuserdatad/UserInterfaceState.xcuserstate

https://www.programmersought.com/article/1594916500/

David Para
  • 101
  • 1
  • 2
4

Nothing worked but this for me, as I wanted to commit Pods that also have .xcuserdata in it:

**/xcuserdata/*
Anthony
  • 804
  • 3
  • 12
  • 32
3

If you used git, you can add .gitignore

# Xcode
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.moved-aside
DerivedData
.idea/
*.xccheckout
*.moved-aside
xcuserdata/
*.hmap
*.ipa
*.xcworkspace
*.xcuserstate // <--- Here
!default.xcworkspace
Giang
  • 3,553
  • 30
  • 28
3

I don't see any logic here. However, in my case only moving xcuserdata/ to the most down of the .gitignore file helped.

AlexR
  • 33
  • 6
1

For me nothing worked, but this

add this line to your gitignore

*.xcuserdata
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
1

Coming late to this question but this site helped me out with this problem:

https://www.gitignore.io/

Specifically using the labes swift and xcode to generate the following:

https://www.gitignore.io/api/xcode,swift

pmckeown
  • 3,419
  • 3
  • 31
  • 35
0

FWIW, my xcuserdata folder was NOT being tracked by git yet and was still showing up in git status. The problem was that I had a space before xcuserdata in my .gitignore file.

Tylerc230
  • 2,883
  • 1
  • 27
  • 31
0

You could simply do

 git checkout -- <file>..." to discard changes in working directory

Example:

   modified:
        mySwa.com.xcworkspace/xcuserdata/bibscy.xcuserdatad/UserInterfaceState.xcuserstate

   git checkout -- mySwa.com.xcworkspace/xcuserdata/bibscy.xcuserdatad/UserInterfaceState.xcuserstate
bibscy
  • 2,598
  • 4
  • 34
  • 82
0
  1. Open Xcode preferences > Source Control > Git (tab)
  2. Under Ignored files add xcuserdata/
  3. Quit Xcode
  4. Clean ~/Library/Developer/Xcode/DerivedData
  5. Re-open Xcode project
  6. Commit (hopefully you shouldn't see the contents of xcuserdata to be committed)

Note: This would work only if the xcuserdata contents haven't been committed already

user1046037
  • 16,755
  • 12
  • 92
  • 138
-2

Simple Way :-)

Add this in your .gitIgnore file and save your file

xcuserdata/

Now run below command in terminal

git rm -r --cached .

now test it Boommmmm .....

:-)
Shakeel Ahmed
  • 5,361
  • 1
  • 43
  • 34