Reputation: 3880
I am struggling with a problem with a merge conflict (see Cannot Merge due to conflict with UserInterfaceState.xcuserstate). Based on feedback, I needed to remove the UserInterfaceState.xcuserstate using git rm.
After considerable experimentation, I was able to remove the file with "git rm -rf project.xcworkspace/xcuserdata". So while I was on the branch I was working on, it almost immediately came back as a file that needed to be committed. So I did the git rm on the file again and just switched back to the master. Then I performed a git rm on the file again. The operation again removed the file.
But I am still stuck. If I try to merge the branch into the master branch, it again says that I have uncommitted changes. So I go to commit the change. But this time, it shows UserInterfaceState.xcuserstate as the file to commit, but the box is unchecked and it can't be checked. So I can't move forward. I cannot even switch back to my branch. The file UserInterfaceState.xcuserstate is showing that it is in the "D" state, which obviously means it has been deleted. Is there a way to use 'git rm' to permanently remove xcuserdata under the project.xcworkspace? Should I attempt to put it back into the repository? If so, how.
Help!! Any ideas?
UPDATE:
I paste the result of git status
Changes to be committed:
modified: project.pbxproj
modified: [a list of all the files to be merged]
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
both modified: ../[projectname]/en.lproj/Localizable.strings
Upvotes: 4
Views: 5912
Reputation: 8671
here are the steps I did to remove xcuserdata/xcuserstate from commits
1- Generate .gitignore from here: https://www.toptal.com/developers/gitignore
2- Add .gitignore to the project using terminal:
touch .gitignore
3- Go to the file in the project folder, open it, and paste the code generated in step one.
4- In terminal while still in the project type git add .gitignore
5- Also in terminal remove the xcuserstate from git by typing: git rm <whole path to xcuserstate>
If you don't know the path, type git status
and copy the whole xcuserstate path from there.
6- Make a commit in Xcode, you shouldn't see xcuserstate file because you added .gitignore
and removed it from git in steps 2 and 5 respectively.
Upvotes: 4
Reputation: 1044
If you deleted the file in the branch, why didn´t you merge your branch into master? that should have been enough.
I think you might have a conflict because you deleted the file in both branches, that´s why you cannot switch from one to the other: you will not be able to do it until the conflict is resolved. To resolve the conflict for this file, just make a commit since it is marked as deleted (D). If you have other files, check that you don´t skip any new added file when resolving the conflict.
Also make sure you have a rule in your .gitignore to ignore the xcuserdata file to prevent git from trying to add it again to the index, have a look to this question: gitignore file for xcode projects
Upvotes: 1