Removed files on branch preventing git checkout - xcode

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.

Related

Delete local changes in Xcode?

I imported an external project into my project by dragging its project file into mine. It didn't work. Now those files show up whenever I check something in. I don't want them and I never select them at checkin, but how do I get rid of them? I don't find them in the underlying file system, and I haven't found any controls that will get rid of them. They appear in the source control navigator under the changes tab as Local Changes.
As far as I understand, you have a project in the local area that you version control with git. You tried something new on the project after the last commit. But you want to cancel the changes and go back to when the last commit was made. In this case you can use the following commands:
# Undo changes made to tracked files
git reset HEAD --hard
# Delete untracked files
git clean -f
# Delete untracked files and directories
git clean -fd
If there is valuable data between the last commit and the current state, you will lose as a result of the above operations. To prevent this situation, you can choose the following way:
# Secure the difference between the last commit and the current state
git commit -m "recovery"
# Revert to two previous commits
git reset HEAD~2
References
How To Undo Last Git Commit
Reset all changes after last commit in git

git on windows says untracked working tree files would be overwritten by checkout but they don't exist

This is a weird one, and I have tried everything both in git and in windows but can't get the message to go away.
I have a folder in my repo as follows:-
/startup
/client
/index.js
/server
/index.js
but for some reason, somehow, at some point, git has appeared to have decided I have 2 other, very similar files, and won't let me checkout my main branch, it forever complains:
error: The following untracked working tree files would be overwritten by checkout:
imports/startup./client/index.js
imports/startup./server/index.js
Please move or remove them before you switch branches.
Aborting
I don't have any such named files (and don't believe I ever did), and the situation is totally compounded by the fact that a trailing "." on a folder name is not something windows plays ball with! If I try to rename my startup folder from "startup" to "startup." it just ignores the change.
I've git cleaned with every flag / flags known to man, git forced everything that can be forced, I've even deleted the entire repo and recloned.
I've checked my central repo too, in all branches (master, the current develop, and my own current branch that I'm stuck in), and of course the "startup." files aren't listed - just the "startup" folder as expected.
So I'm at a loss, and putting this out to the community in the hope that someone else can help.

Ios git merge conflict in 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.

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: 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