42

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,095
  • 13
  • 148
  • 192
Fernando
  • 1,233
  • 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

10 Answers10

47

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,233
  • 2
  • 12
  • 17
10

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
  • 3,700
  • 11
  • 39
  • 93
NFerocious
  • 3,103
  • 2
  • 16
  • 40
5

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
  • 51
  • 1
  • 1
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,341
  • 28
  • 26
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
2

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

**/xcuserdata/*
Anthony
  • 754
  • 2
  • 10
  • 31
1

For me nothing worked, but this

add this line to your gitignore

*.xcuserdata
Qadir Hussain
  • 8,708
  • 11
  • 87
  • 123
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
  • 2,696
  • 1
  • 29
  • 33
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,846
  • 1
  • 25
  • 30
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,346
  • 3
  • 26
  • 70