Ios git merge conflict in xCode - xcode

I have two branches in my project, one is develop and other is master, accidently without merging develop into master I made app live and now I have two different versions on two different branches. Let's say 1.5 version on master and 1.6 on develop, now when I tried to merge these two branches git show merge conflicts in 3 different files,
.plist
.xcodeproj
.xcworkspace
after merge when I tried to open xCode project, it failed and show error "project cannot be load.." when tried to open files manually it just doesn't open in editText. I tried sublime editor but then again I couldn't locate conflict as there were a lot of lines of code.

If you want to replace master content with dev, you should:
do a merge from master to dev, keeping dev content
then do a trivial merge from dev to master
That is:
git checkout dev
git merge --ours master
git checkout master
git merge dev

You can resolve conflicts by keeping any version (keep mine or keep theirs) of this files as they save the xcode status but they don't have your code and should not have been tracked. But don't resolve the conflicts yourself, just choose one of the versions and the project should work.
You are having this problem because you should have created a .gitignore file in your repo before creating any other file to avoid having problems with files that your ide uses but don't have the code of your app.
To avoid problems from now on, you can create the git ignore file with this content and add it to the repo.
But there are files traked that should not be. So execute this commands:
git rm -r --cached .
git add .
git commit -m "use .gitignore file"
This will delete everything from the index and add the files again applying the gitignore rules.
Check that all is working and git push to your server and you should not have more conflicts with this files for saving the xcode status.

Hello #Najam you can make change in remote branch push it to master and then try to merge remote and master
git merge remote mater:master
or you can delete the remote branch and push your remote code to master branch.

Related

Github how to push Xcode project without old files and folders?

I finished an Xcode project and pushed it to github from Xcode 'Source Control' Menu. Then I changed the project name CountryBook to Countries. I Built project and ran. Everything was okay. Then I coiped project folder to desktop as a backup. Then pushed project again. Everything has messed up. Some old named folders and files still exist in repo. Then I deleted every directory and file from github repository. Now, backup version of project is working. But when I try to push it to repo, old files are still exist. I deleted 'origin' from 'Remotes' and created a new repo named 'Countries'. I pushed project again but it was same. A mixed version of old files and new files. When I clone the github version of project, of course it is not runnable. What sould I do and how can I push clean version of my project? I don't want to lose project.
This is Countries repo now:
This is my working project folder with correct content:
I would fix it via command line, lets assume you start from scratch:
Step 1 - prepare the working branch:
Clone the project
Navigate to root folder of the project
Checkout the main branch ("main", "master", or whatever it is)
Create a new branch you will be working with
git clone https://github.com/yourorg/yourrepo
cd yourrepo
git checkout main # or master
git checkout -b fixprojectstructure # branch name can be anything
Step 2 - clean project locally
Delete old project, old workspace, ensure the names in Podfile and Podfile.lock are fine
Build the project and ensure it's working
Step 3 - commit your changes:
# assuming you are in the root of the project
git add .
git commit -m "Some explanation"
Step 4 - push your changes:
I usually do it the lazy way: just run git push, which will show you the proper syntax to push remotely, something like
> git push
fatal: The current branch fixprojectstructure has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin fixprojectstructure
> git push --set-upstream origin fixprojectstructure
Enumerating objects: ...
...
remote: Create a pull request for 'fixprojectstructure' on GitHub by visiting:
remote: https://github.com/.../pull/new/fixprojectstructure
remote:
...
Branch 'fixprojectstructure' set up to track remote branch 'fixprojectstructure' from 'origin'.
Step 5 - merge your changes:
Basically just do what the line above is saying:
Navigate to https://github.com/.../pull/new/fixprojectstructure
Create pull request
Merge pull request to main (or whatever the initial branch was)
Note on the side: configure the gitignore file properly for your repo as well. For starters, follow the gitignore template to create a proper gitignore file, and then change it the way you need to.
For instance:
Usually, if you use cocoapods, you do not store .workspace folder and its contents in the repo. Instead it's generated using pod install command on each machine that needs it.
It's also common to exclude Pods directory from storing in the repo, although there are pro / cons arguments both ways.

I have deleted my project.pbxproj file using git checkout -- <file>. Should I delete the branch locally and pull from origin?

I have gotten myself into some hot water regarding source control.
I had just gotten a feature branch to work that another developer on my team had created and developed, which required adding some files. He then added some additional code to the project, and I wanted to revert to the version of the branch I had started with before I pulled his new code so that I wouldn't have to worry about merging these new files.
So, as per git's recommendation, I unstaged the changes I had made and used:
git checkout -- ScrollingTextLabels.xcodeproj/project.pbxproj
followed by:
git pull
I had assumed that the pull would replace the project.pbxproj file with the one from the origin, but instead git spat out a lot of lines beginning with "delete mode", most disconcertingly:
delete mode 100644 ScrollingTextLabels.xcodeproj/project.pbxproj
Every time I try to open the project on this branch, I now get the following error message from Xcode:
Project /Users/myname/Documents/Code/organization/product-ios/ScrollingTextLabels.xcodeproj cannot be opened because it is missing its project.pbxproj file.
I have been able to switch to other branches, which are still working fine, and must have their project.pbxproj file.
Also, I attempted to use git reset --hard to no avail. Should I force an overwrite (a la How do I force "git pull" to overwrite local files?)?
Should I delete the branch locally and pull from origin?
All I want is for the remote version of this branch, which is working well, to appear unchanged on my computer so that I can open it and continue working.
The message
delete mode 100644 ScrollingTextLabels.xcodeproj/project.pbxproj
during a merge (or pull) indicates that the file was deleted in the to-be-merged branch. It does not exist anymore in the other branch, your co-worker must have deleted that file.
Deleting a branch and pulling does normally not solve anything. You already have all changes from the remote (probably in origin/branch). Either checkout a new branch from that commit, or reset to it (potentially losing all your local changes!)
Use git log origin/branch or gitk to view the changes of the branch. You can also show the log for this single file only with git log origin/branch -- ScrollingTextLabels.xcodeproj/project.pbxproj. This should tell you, what happened to the file and whether it was deleted in the branch.

git delete all files form remote branch after updating .gitignore

I recently started working on an open source project called "TFDT : Team Foundation Dev Tools" but I made a mistake to add a std .gitignore and now I want to fix it by adding one from https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore
I've already 10 or so commits by now and I've two branches. Is it still possible to get rid of all undesired files from GitHub's both branches that I've now ?
At the same time I also want to make sure that if someone clones my repository, they should be able to build successfully as long as my code builds on my development machine.
Compatibility : VS 2k 8, 10, 12, 13
One solution I have done is to rename the files, check them in, then rename them back to the original file name and check them in again. For example, if you want to gitignore a file called config that is already tracked, add it to .gitignore then:
git mv config config.temp
git commit -am "renaming file for gitignore"
git push origin master
git mv config.temp config
git commit -am "renaming file back to original name"
git push origin master

Removed files on branch preventing git checkout

In my project I've got 3 branches :
- master
- dev
- sync
I've done a bunch of work in sync, and somewhere along the way got fed up of committing xcode project files that I changed my gitignore to exclude them, stopped them being tracked, and removed them. This is fine, but now I want to merge my changes on sync back into dev.
Every time I try and checkout dev in order to merge, I get the error :
error: The following untracked working tree files would be overwritten by checkout:
ManagePlaces/ManagePlaces.xcodeproj/project.xcworkspace/xcuserdata/Aidy.xcuserdatad/UserInterfaceState.xcuserstate
ManagePlaces/ManagePlaces.xcodeproj/project.xcworkspace/xcuserdata/Aidy.xcuserdatad/xcdebugger/Expressions.xcexplist
ManagePlaces/ManagePlaces.xcodeproj/xcuserdata/Aidy.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
ManagePlaces/ManagePlaces.xcodeproj/xcuserdata/Aidy.xcuserdatad/xcschemes/ManagePlaces.xcscheme
ManagePlaces/ManagePlaces.xcodeproj/xcuserdata/Aidy.xcuserdatad/xcschemes/xcschememanagement.plist
Please move or remove them before you can switch branches.
I understand why this is happening as the dev branch hasn't had these files removed and is still tracking them, but how can I get around this?
Just add --force to your checkout command.
I believe you can do this:
git checkout -- <file>
This should reset them to the last commit.

Git: cannot open .pbxproj file error after renaming Xcode project and pulling changes

I renamed our iOS project (client finally chose a name) following instructions in the most upvoted answer here. I pushed my changes. Now, when my teammates pull, they cannot open the project because Xcode cannot find the .pbxproj file. They subsequently reset to their good local versions.
As usual when I royally f**k up I tried a hard reset to the last good commit, planning to force push the good commit up to the remote. While the reset was 'sucessful', it didn't change the newName.pbxproj back to oldName.pbxproj. So I could not open the project. Checking out my faulty commit didn't help things either. I am back at square one.
.pbxproj is NOT in our .gitignore:
*.DS_Store
*.xcodeproj/xcuserdata/*.xcuserdatad
*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
*/*.xcodeproj/xcuserdata/*.xcuserdatad
*/*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
The only thing I can think of now is to reclone the project from a specific remote commit. How can I do this? Other options? Why won't a renamed .pbxproj transfer over in a pull?
If you do a git log -5 it will show your last 5 commits. Determine the version before you named the file, and you can do a git reset --hard HEAD~<number> where <number> is how many commits you want to go back.
Alternatively, with your renamed proj file, you could try to blow away your remote with a git push origin :branchName then push your local changed branch up to the remote git push origin branchName
Then, have your other team members do a pull from the newly pushed remote.

Resources