2

I got a problem when I wanted to push source code to remote control. But xcuserstate file was always changed, and Git announce "Commit or discard the changes and try again". So I tried to ignore xcuserstate file but I can't enter image description here

How can resolve it ???

DungProton
  • 229
  • 3
  • 7

1 Answers1

3

the error-message is pretty specific in what you ought to do: either commit the file (if you want to keep the changes) or discard it (if you don't care about the changes).

the cuser-files are usually hidden deep in the xcode-project, so you might want to provide the full path to them (the following examples use find to find those files in subdirectories)

commit

this will commit all cuser-files in your current directory:

$ git add $(find . -name "*.xcuserstate" -or -name "*.xcuserdata")
$ git commit $(find . -name "*.xcuserstate" -or -name "*.xcuserdata") -m "updated xcuser stuff"

discard

this will discard changes from all cuser-files in your current directory:

$ git checkout $(find . -name "*.xcuserstate" -or -name "*.xcuserdata")

generally you don't want to track the xcuser-stuff at all, so you should remove it from the repository and make sure it doesn't get added accidentally:

# remove cuser-stuff from the repository (but not locally)
$ git rm --cached $(find . -name "*.xcuserstate" -or -name "*.xcuserdata")
# commit the file removal
$ git commit $(find . -name "*.xcuserstate" -or -name "*.xcuserdata") -m "don't track cuser stuff"
# prevent the cuser-stuff from accidentally adding it
$ echo "*.cuserdata" > .gitignore
$ echo "*.cuserstate" > .gitignore
$ git add .gitignore
$ git commit .gitignore -m "don't track user-specific data"
umläute
  • 28,885
  • 9
  • 68
  • 122