Merge conflict while trying to merge stashed code - xcode

So I stashed my changes for my Swift project so that I could make a pull request and then merge the changes I made with the new pull. However, whenever I try to merge my changes I get a merge conflict, regarding the UserInterfaceState.xcuserstate XCode file. Nothing I'm trying is allowing me to merge my stashed code, and I'm worried that I'm going to lose an afternoon's worth of code.
I tried adding *.xcuserstate to .gitignore, but that didn't seem to do anything. I then tried deleting the file, which created a modify/delete conflict from the version in the stash. Here's the error I'm getting when I try to get the stashed code:
$ git stash apply
CONFLICT (modify/delete): myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate left in tree.
Trying what Flows recommended this was the output I received:
$ git reset --hard
HEAD is now at e509ffa Fixed bugs
$ git stash pop
myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate: needs merge
unable to refresh index
$ git rm myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate
myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate: needs merge
rm 'myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate'
$ git stash pop
CONFLICT (modify/delete): myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate left in tree.
Is there anything that I can do to fix this? Nothing seems to be working, so any help would be greatly appreciated, thanks.

You can try this
Reset master with --hard option to origin/master
Apply the stash with stash pop
Git should tell you there is a conflict. Edit UserInterfaceState.xcuserstate file to see the conflict and correct it.
git commit
If it doesn't work, could you paste all git output of the commands ?

Related

git clone did not pull all the merged files

Another developer created a branch, worked on it, and checked in code. He also did a merge from that branch to the master. Before cloning I see the merged files in the master. But after cloning from master via xcode, it did not pull the files that were checked into branch and subsequently merged into master.
I thought after merge anyone should be able to checkout master and clone and get all the merged files. But that is not happening. How to pull the entire merged code?
When I run git status, I get this output:
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: xyz/xyz.xcodeproj/project.pbxproj
modified: xyz/xyz.xcodeproj/project.xcworkspace/xcuserdata/HCCS.xcuserdatad/UserInterfaceState.xcuserstate
modified: xyz/xyz/Base.lproj/Main.storyboard
Untracked files:
(use "git add <file>..." to include in what will be committed)
MyPlayground.playground/playground.xcworkspace/
MyPlayground2.playground/playground.xcworkspace/
compare.playground/playground.xcworkspace/
no changes added to commit (use "git add" and/or "git commit -a")
I am at loss to understand the error and why it is not pulling all the files when cloned.
Some more details:
git pull
error: Your local changes to the following files would be overwritten by merge:
r2nr/r2nr.xcodeproj/project.pbxproj
r2nr/r2nr/Base.lproj/Main.storyboard
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
MyPlayground2.playground/playground.xcworkspace/contents.xcworkspacedata
compare.playground/playground.xcworkspace/contents.xcworkspacedata
Please move or remove them before you merge.
Aborting
I ran git stash
git stash
'Saved working directory and index state WIP on master: 6d9b3d2 Merge branch 'branch01' Added ProviderApiCaller class to the code
HCCS#CEASJ311-4293 green-synapse % git pull
Updating 6d9b3d2..35d2b7e
error: The following untracked working tree files would be overwritten by merge:
MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
MyPlayground2.playground/playground.xcworkspace/contents.xcworkspacedata
compare.playground/playground.xcworkspace/contents.xcworkspacedata
Please move or remove them before you merge.
Aborting
So I removed the three files:
MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
MyPlayground2.playground/playground.xcworkspace/contents.xcworkspacedata
compare.playground/playground.xcworkspace/contents.xcworkspacedata
Next
git pull
That seemed to work
Then I enter xcode project
I get error
The project ‘r2nr’ is damaged and cannot be opened due to a parse error. Examine the project file for invalid edits or unresolved source control conflicts. Path: /Users/HCCS/myproj/r2nr/r2nr.xcodeproj.
How to resolve conflicts?
*
While git stash will save (and then git reset --hard to remove) modified files, it does nothing about untracked files by default. It seems likely that your "Another developer" committed the untracked files, which was probably a mistake on his or her part; that's what produced the errors with the untracked files.
(You can use git stash -u, but I prefer to avoid git stash in general, and git stash -u is particularly nasty to work with, so I would suggest not doing that.)
In any case, after removing your own untracked files, your git pull appears to have worked. Remember that git pull means:
run git fetch; then
run a second Git command of your choice, either git merge or git rebase
and—assuming the git fetch itself works, which it usually does—the second command may stop in the middle, or complete. The output from the command tells you which of those happened. But assuming it completed successfully, all your Git problems are now solved.
[but xcode now says]
The project ‘r2nr’ is damaged and cannot be opened due to a parse error. Examine the project file for invalid edits or unresolved source control conflicts. Path: /Users/HCCS/myproj/r2nr/r2nr.xcodeproj.
Given that your "another developer" appears, from what we know above, not to understand how to use Git, perhaps this same person committed unresolved conflicts, rather than resolving them. This is now an xcode problem, but solving it may require that you discard the other developer's work and re-do it yourself, or repair anything he or she damaged. You cannot use normal Git tools to resolve a conflict here as the conflict is already resolved (incorrectly, apparently).
In general, I recommend since Git 2.23+
git config --global pull.rebase true
git config --global rebase.autoStash true
That way, a simple git pull would stash your work in progress for you, pull, rebase your local commits on top of the updated branch, and unstash.
Then you can start resolve any conflict.
But if those are too complex regarding, you can force your own version with:
git stash show -p | git apply && git stash drop

git pull added tons of untracked files and modified files

I am not very familiar with git as I just use it in the most basic manner. Lately I've been running into this strange behavior which makes no sense to me and causes a huge disturbance in my productivity. For certain branches when I run git pull instead of just getting the latest commits from the remote repository like I expect, I get an ENORMOUS list of modified/deleted/added files as well as an enormous list of untracked files. The branch I am pulling from is our team's master branch. I am just trying to keep my local copy of master in sync. What are these other untracked files showing up as well as these modified files? I didn't touch any of these other files.
What makes the problem worse is that I can't delete these untracked files or anything. I've tried `git clean -fx' and it only removes 3-4 files but still leaves hundreds. At this point I just want to get rid of all of these files, delete the branch, and pull the branch from remote again.
I tried doing the following:
git fetch --all
git reset --hard origin/<remote_branch_name>
but I received an error because Git couldn't create a symbolic link. I am using Git on Windows.
Why is git pull doing this, and what should I do?
EDIT: I was finally able to run the git reset command when I ran my prompt as an admin, but it still doesn't explain this weird git pull behavior.
It seems to me that the 'git pull' action did not complete successfully.
It is possible that you modified some of the files as an admin, and when pulling as non-admin user git tries to modify or delete a file and has no permissions to it.
Therefore you stay in some half baked state.
What do you see when you run git status?
Is there any error in the git pull?

Why doesn't Git track files modified in Xcode?

I'm using Git on the terminal to commit changes & push them to a remote repo.
Git can recognize when I create a file or modify a file via VS Code. However, when I work on my files on Xcode and save them, Git doesn't track any changes. It tells me:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
What's the problem and how can I fix it?

Xcode 9.2 - Version control - how to revert back to earlier committed version

Im using Xcode 9.2 with bitbucket for version control. I have the past 4-5 hours worked in the master branch. I realise now that I want to keep the work that I have done today but not part of the master branch but rather as a new branch.
I have been able to push the existing version to the new branch, but it required me to commit to master first (locally).
Now I want to revert the master back to the version from yesterday, and commit this at the master. This is where the problem occur. I am able to revert back to the previous committed version by checkout the commit - but then I am not on the master branch anymore, and I can't commit to master or push to master.
How can I revert back to the master to a previous build, and basically remove the changes done the past 4-5 hours?
For the next time you realise before you commit:
Open up terminal
cd ${path to your project}
run git stash command
When you stash the not commited changes, now you should be safe to switch and make new branch
now change to the new branch and apply stash: git stash apply
Enjoy your changes.
Since I am confused as hell and this happens to me from time to time, I created alias in my .bash_profile file to delete the local commits by simply making one command in terminal:
alias fixFuckup="git reset HEAD~1"
simply run the command and you will be reset to the state before the commits. Actually this resets one commit.
git reset HEAD~1
to reset to the state before doing lot of commits, prefer using this.
git reset --hard HEAD^
for clarifying the changes please take further look at this:
what is difference between 'git reset --hard HEAD~1' and 'git reset --soft HEAD~1'?

Accidentally deleted xcode project files via Git commands

I accidentally deleted all my files by committing a new build, then deleting that commit. (git commit -m, git reset -hard HEAD^). Then I tried to use (git merge ) to undo the delete. I noticed that all the missing files were back, but all the contents were missing. To clarify, all the files that were missing after I deleted the commit was back, but contents of those files only included default Xcode markups and all my coding was still missing. Is anyone familiar with an issue like this? Any guidance would be greatly appreciated..
Steps:
git commit -m
git reset -hard HEAD^
git merge
You should be able to use git fsck to see any dangling blobs or commits which remain after a reset.
git fsck --cache --no-reflogs --lost-found --unreachable HEAD
You'll see something like this with any dangling objects:
Then just do git show with the blob id to inspect
git show fd2274ea24e214457fa865e6aa74a0a1b036291a
If it's the file you want, you can then write it to a file using git show {blob id} > filename. e.g.
git show fd2274ea24e214457fa865e6aa74a0a1b036291a > test.txt

Resources