git clone did not pull all the merged files - xcode

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

Related

xcode binary file checkout and push to git hub causes issues

Add, commit to a local branch repository,
git add *.*
git commit -m "msg"
I push code to remote branch
git push branch
I get the same error on a Xcode specific file
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: abc/abc.xcodeproj/project.xcworkspace/xcuserdata/axz.xcuserdatad/UserInterfaceState.xcuserstate
I have to add and commit that file again and then push works
Next I merge my branch into main
git checkout main
git merge branch
I get same error on the same file
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: abc/abc.xcodeproj/project.xcworkspace/xcuserdata/axz.xcuserdatad/UserInterfaceState.xcuserstate
I have to add and commit the file and then push
git push
Then it works.
I don't know why this specific file does not get included in the initial add/commit/push and I have to perform add/commit/push separately on this specific file.
This file UserInterfaceState.xcuserstate is specific to user I assume. As I work in team, so will I be overwriting someone else's UserInterfaceState.xcuserstate file? Can someone explain?
xcuserdata should be ignored from source control, you can add it to your .gitignore.
xcuserdata/

Binary file showing as modified after git checkout

For some reason, after cloning a repository and changing branch I had one jar file marked as modified (without being modified) and I can't seem to un-modify the file (which prevents merging branches.
PS D:\src\expm> git status
On branch epic-my-wallet
Your branch is up-to-date with 'origin/feature-01'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Test/Selenium/selenese-runner.jar
no changes added to commit (use "git add" and/or "git commit -a")
I tried to undo with the checkout command
PS D:\src\expm> git checkout -- .
git status output the same exact message as previously.
I tried to reset it from HEAD with
PS D:\src\expm> git checkout -f HEAD
Your branch is up-to-date with 'origin/feature-01'.
Please note that jar files are flagged as handled by LFS in the .gitattributes file
*.jar filter=lfs diff=lfs merge=lfs -text
Not quite sure on the next step here. The file has not been modified since its commit months ago.
edit
I should add that today we tried to reset the cache with git rm . -r --cached and removed the LFS cache as well (physically remove the .git/lfs folder) and re-download the files with git reset --hard.
Due to your git setting to handle end of line, which should be to 'autocrlf', git modify/corrupt the jar file at checkout!
You should add a '.gitattributes' file in your repository where you set the 'jar' files as 'binary' and git will no more try to convert end of lines.
That's the recommended way to handle end of line in a git repository to solve such problems...
It seem the problem was linked to Git LFS in some way. We upgraded both Git (from 2.8.4 to the current at 2.9.3) and Git LFS (from 1.2.1 locally to the latest 1.3.1 at the moment). Then deleted and re-added the jar file.
We did a clean clone on a new folder after that and the problem seemed to be resolved. Could be the upgrade of git + lfs that resolved the issue.

Merge conflict while trying to merge stashed code

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 ?

Why are "ghost" folders with a weird "\200" character appearing in git? [duplicate]

This question already has answers here:
Remove a file with a strange name from git
(3 answers)
Closed 7 years ago.
TL;DR summary
Weird files appeared. They show on git but not on disk. A list of possible programs causing that are listed.
Why did they appear?
How can I get rid of them now?
There is a weird \200 character I cannot type.
For the record: the solution that worked for me is the second answer of user VonC: https://stackoverflow.com/a/13250936/1255826
I already had to copy all the files and make a new Git repository, removing the .git folder from my project to try and fix this. git status claims there are modified files/folders with a very strange \200 character in their name, when actually I didn't add those.
To clarify, I cannot see any file with those names on my disk. I can only assume there is something weird going on in the .git folder. I've tried to see if there are any hidden files with that \200 part in their name. There aren't. (I even have the "show hidden files and folders" option enabled on my computer):
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls
es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls -ahf
. .. es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$
See my terminal log here to see exactly what I mean.
Note that git status didn't show these files, that were added a second later when I used the git add -A command. Then, after that, these "ghost" files are shown:
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul 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 checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
Untracked files:
(use "git add <file>..." to include in what will be committed)
laboratorio/lab5/es3/.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git add -A
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: laboratorio/lab5/es3/.gitignore
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
new file: "laboratorio/lab5/es3/src\200student/student.c"
new file: "laboratorio/lab5/es3/src\200student/student.h"
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
deleted: "laboratorio/lab5/es3/src\200student/student.c"
deleted: "laboratorio/lab5/es3/src\200student/student.h"
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$
I've already tried in the past to ignore this, and push the changes to github anyway, but then the same files/folders are shown in github, although when I click them I get an error page (404 or 500, I don't remember the error code).
Also, if I try to delete these with a del or rm command, it says the file doesn't exist. I don't even know if I can type the character that stands for the \200 escape code.
I might have to try and type that character when I use git rm <PATH/TO/FILE> instead of just trying to do del or rm, that do not work.
Why are these files/folder being created? Is it just a bug?
I'm working with a combination of these tools and programs: cygwin64, mingw64, gcc, make, splint, netbeans, atom (editor), git on Windows 10 x64. Is any of these the cause of the error?
My project folder is under C:\\Users\%USERNAME%\repos\algoritmi2016.
splint and git are installed both with and without cygwin. mingw64 is installed normally on Windows' cmd. gcc and make are installed under cygwin. Most of the time I am just using cygwin which points correctly to the cygwin version of splint, git, gcc and make.
I'm not using the atom shell commands, just the GUI editor.
I used Netbeans and atom only inside the ./laboratorio/lab5/es3 folder of my project. In that folder I have the Netbeans project files .project and nbproject.
On cygwin I have a symbolic link in my cygwin's home folder called repos pointing to my normal Window's %USERNAME%\repos folder. I use this link to navigate with cd quickly to my repos folder.
I tried to remove src\200student/ (is it even a folder?), using git git rm -rf ./*student --cached: it didn't match any file, unfortunately.
Is there something wrong in my setup causing this problem?
These files get added to your commit when you issue the command git add -A. If you don't want them, just don't use the -A option to git add. Instead, I recommend only adding the files that you actually want to add to your git repository, one by one.
I don't know where they are actually coming from, however. My guess is that your IDE creates these files for metadata and / or backup while you have the files open. You probably don't have to worry about them, just don't add them into your repository. Next time you want to add somefile.cpp (and maybe it's header, too), just issue the command to add only that file:
git add somefile.cpp
git add somefile.h

Git won't revert or commit a file that it thinks is modified

I've converted an SVN repository to Git by following this tutorial. And now cannot seem to extract a sub-repository like suggested in this answer.
Forgive the long post but most of the text is the nicely formatted git output.
OS: Windows 8
Command line: MinGW
Git version: 1.8.1.msysgit.1
The process of extracting a subrepository doesn't seem to work unless you have a clean staging area and no modified files.
git status tells me that I have a modified file even though this is a fresh SVN import. Ok, let's just try and get rid of it.
Try and revert the file.
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
user$ git checkout -- "folder with space/folder/toolbar.png"
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
This didn't work, but I don't really care if I commit it so I'll try that next.
user$ git commit -a -m "Testing if committing fixes it"
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
Committing by skipping staging doesn't work, so let's try and stage it first.
user$ git add "folder with space/folder/toolbar.png"
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
Doesn't work, so I'm stumped... Go and ask someone smarter.
I'm new to git but am familiar with Hg and have been reading this online tutorial to get myself started.
It is entirely possible that I've messed up a simple command.
Already tried:
I looked around for a solution to my particular problem but have had little luck. I've stumbled across this answer which seems related but does not quite fix my problem.
Edit: Things that might be interesting
This is the part that confuses me. I've pushed this repo a while ago into an online repository. After a fresh clone the repo still thinks that the file is modified (i.e. git status returns the same result, and I've already set git config --global core.autocrlf false and verified by running git config --global core.autocrlf which indeed returns false).
Edit 2: Fix found, but the problem is still not understood
I've managed to fix the repository by simply removing the file from the system, the staging area and then committing the changes.
After this to get the file back I've simply copied it back and committed it to the repository.
The problem, though fixed has only confused me more.
While I was playing around with removing the file I noticed that if I reset the repository to the HEAD, whose last commit has removed the file, git status would indicate that nothing has changed and that the file is not tracked but the file would be restored in my working tree. This is odd considering that it is flagged as removed in git...
Only after removing it a second time, even though git no longer remembers it, did I manage to actually remove it so that git reset and git reset --hard don't restore the file.
If somebody can please explain how I got into this state and if it is a bug in git or normal behavior I would greatly appreciate it.
My suspitions
I've lost the sequence of commands that I used but what happened went something like this:
The file is Images/toolbar.png, and I've navigated into the Images folder.
After I deleted it from the file system git detected the change like so:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: toolbar.png
# deleted: ../images/toolbar.png
#
Note the fact that the images folder is not capitalised! This is being run in Windows which ignores the path case. I suspect that this might be a part of the problem...
I'm really confused but my problem is gone. So this post remains only as a curiosity, although I can't replicate the behaviour it lives in the conversion from SVN somewhere.
I had a similar issue a while back.
Did the capitalization on this file, or the directory it was in change at any point?
I had a directory with a capital letter that was changed to all lowercase (let's say it went fromt /Foo to /foo). It gave me all the same problems you've described.
Whenever I modified a file, it gave me similar output to this:
# modified: bar.txt
# modified: ../Foo/bar.txt
I also had the same problem where committing or resetting wasn't producing any results.
I think the cause of the problem is that Windows file paths are not case-sensitive, but Unix ones are. Since a lot of these command-line tools like Git are developed on Unix-y systems, they sometimes don't handle this difference well, and can get confused when a file is added as Foo/bar.txt and foo/bar.txt. I think this makes Git think there are two different files, where there's actually only one.
My eventual fix was the same as yours, remove the entire directory from history, then re-adding it (and never changing the capitalization ever again). This also caused the same weirdness you described where I had to remove it twice before it took.
Anyway, I know this isn't a definitive answer, but I've since been able to recreate the problem, so I'm pretty sure that's what caused it (at least for me).
I had a similar issue caused by having two files with the same name as my computer saw it.
Message I kept getting:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: images/contact_seller.GIF
#
It happened because the repo's initial commit was done from MacBook that is formatted case-sensitive and the error was appearing on my iMac that was formatted case-insensitive.
On the case-sensitive machine you could see two files
SwedishChef$ ls images/contact_seller*
images/contact_seller.GIF images/contact_seller.gif
Which isn't valid on the second machine so git had to do something about it.
I just had to rename the file and commit those changes.

Resources