0

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? *

vrao
  • 545
  • 2
  • 12
  • 33
  • @matt (and OP): it looks like you're using macOS and xcode here. Perhaps one of the `modified:` path names appears in both upper and lower case due to the other developer using a case-sensitive file system (probably on Linux, but you can create them on macOS). That could produce *some* of the above right after `git clone`. – torek Jul 04 '22 at 01:33
  • That must be an xcode error; Git does not have "project files" in the first place. But I will point out that nobody can diagnose the problem if you're not actually showing us the problem! That's like taking your car into the mechanic, and when he says it seems to be working fine, you say "oh, the problem isn't in the car I drove to you, it's in the one I can't drive". – torek Jul 04 '22 at 02:08
  • Edit the question - you can put code blocks into questions, but not into comments. – torek Jul 04 '22 at 02:49
  • Updated the original post. Hope it helps explain my issues and get some help from experts – vrao Jul 04 '22 at 03:11
  • wording : in the title and your first paragraph, it looks like you are using the word "clone" when you mean "pull" – LeGEC Jul 04 '22 at 05:42

2 Answers2

0

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:

  1. run git fetch; then
  2. 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).

torek
  • 448,244
  • 59
  • 642
  • 775
  • The other developer has saved a backup. So I can discard his work and then ask him to redo it. How to discard his work and then make this work for me. I cannot even open xcode.proj file. – vrao Jul 04 '22 at 04:07
  • Looks like my other option is to go back to my working code, and discard all the other developer changes. I have to build new repository in github and keep working on it. I pull in other developer's code from his back up into my new project, resolve conflicts, push to new repository. The other way -the other developer creates a new branch on the old repository, resolve all conflicts and push it to master and then is it possible to pull from old repository to new repository. Can you advise? – vrao Jul 04 '22 at 05:30
  • Depending on how the other developer did his commits and merge, you may be able to just point a branch name to his last commit *before* his merge (`git branch his-work merge-branch-name^2`), then use `git reset --hard` or create yet another branch name just before the main-branch merge, and do your own merge (perhaps after fixing up his commits). – torek Jul 04 '22 at 17:26
  • I decide to start from an older build, created a new repository, and pushed code. Now I have a main (default) and a master on the new repo. After push it says This branch is 2 commits ahead, 1 commit behind main. How to fix this? – vrao Jul 04 '22 at 21:17
  • Why do you believe this is wrong / needs fixing? You have two commits they don't; they have one commit you don't. What would you like to do about this situation? Do you want their commit? Do you want to give them your commits? Do you want to combine work from these commits? This is the sort of thing Git is about: learn to work Git (perhaps on something less important to you ), then *use* Git as the tool it is to achieve the results you want. – torek Jul 04 '22 at 21:28
  • I gave up my commits with git reset HEAD~2 on the branch with conflicts. Now what commands should the teammate run to be able to avoid all conflicts? Is it checkout branch, pull, compile/test, and then push – vrao Jul 04 '22 at 23:27
  • Conflicts are not something to be *avoided*. Again, you and your colleague just need to learn *how to use these tools* (assuming you want to continue to use these tools). – torek Jul 05 '22 at 01:18
  • Created a conflict branch, reset my commits, teammate fixed it. – vrao Jul 06 '22 at 03:59
0

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250