Xcode merging issue - xcode

I am attempting to merge two branches, but I have four files with a "C" icon at the side of the file name, like the following:
No matter how I click the file, I cannot open it.
Meanwhile, the bottom right "Merge" button is inactive, and I am guessing that the cause for unable to select "Merge" is the icon beside the file name. Can anyone tell me what does that sign mean? And If resolving the problem with the "C" icon is enough to make the "Merge" button active so that I can merge two branches successfully?
After I click on the "C" file, and then click on some other files with A, there is a message says:
The source control operation failed because the file “XXX” could not be found. Make sure a valid file exists in the repository and try again.
I understand that I added some new files that the other branch does not have, so I guess this is the other cause for me not able to merge the two branches? However, I am confused that, if I were to fix the alert and the new file exists in the repository, doesn't it mean that I actually successfully "merge" the two branches, sine the old branch would then contain the new file? Could anyone provide any insight in this?

https://stackoverflow.com/a/20033446 helped me solve this. There was an untracked file causing the issue. The file was there on both tracks but somehow it wouldn't work.
What I did was the following:
Add the problematic file name to the .gitignore in both repos
Close Xcode
cd into main branch
git rm -r --cached .
open the project, change a file and commit.
Exit Xcode to do git add .
Open Xcode and commit again, push
cd into the problematic branch
git rm -r --cached .
open the project, change a file and commit.
Exit Xcode to do git add .
Open Xcode and commit again, now pull
Do a change, commit and push.
Now in your main, pull once again.
Both dirs are now on the same state. Edit your .gitignore file to add the problematic file back in, push from this dir and pull from the other dir.
Now both have the same clean state with the problem file included.

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

Why are subfolders not being seen by the Git repository?

I have just created a local repository (using Git) for a project that will contain many subfolders (it is a pedagogical project with Lesson 1...2...3 etc..., each one with a folder within the main directory).
I connected this to the remote repository I created on GitHub.com and hoped that would have been enough to start working, pushing, committing etc... now that I have created the first Xcode project inside the main folder neither Xcode Commit function nor Terminal git commit command is seeing any change.
The symptoms I see are that the remote repository sees "Project name" folder, then "Lesson 1" folder inside it but nothing else inside "Lesson 1", where the Xcode project should be (it actually is there in the Finder).
What may have gone wrong?
What would have been the proper set of actions to create a repository in a directory that would automatically fetch every new file added to it?
Thank you so much!
Git will not automatically track new files you create in the directory tree which contains your local git repo.
When you create new files, you need to inform git that you want them tracked, with the "git add" command.
git add path-to-new-file
If you create new files and do not add them, then when you run the "git status" command the output should contain a section labeled Untracked files, like this:
Untracked files:
(use "git add ..." to include in what will be
committed)
asdf.txt
It will show the path to the file(s) relative to the top of your git repo, including the filename(s). Pass all of that to the git add command. Then commit, just as you would for changed files.

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.

Committing source to git via Xcode, failure to commit

I have a repository, in which i code. Once some changes are made, they are checked in to GIT repo via Xcode.
Before checking in .. files look like this - files i have changed look right
Upon checking the code in (Alt-Command-C), all i see is (Note that files seen in explorer window are not seen)
Towards the bottom of the screen, correct number of files are shown
When commit button is hit, no errors are shown, all looks normal, however, nothing (visually) changes:
Explorer continues to show same files modified
Commit screen continues to show some files in need of being committed
Commit screen does NOT show exact files to be committed
I could have sworn that last night all files were committed. Could someone help me understand what's going on here?
UPDATE:
After modifying my .gitignore to include
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
project.xcworkspace/
xcuserdata/
.DS_Store
*.tm_build_errors
You should probably create a .gitignore file and put it in your directory. The xcuserstate files are constantly changing (and are of no use to your overall commits). Your will always show changes and it will also prevent you from pushing your changes to your remote (if you have one).
There are plenty of places that will show you how to make a good gitignore file.
Git ignore file for Xcode project
The issue it seems was that in my set up, Xcode defaults to File View
When I switched to Flat View, files which were changed showed up
First thing to try it to try to commit the files from the command line.
Run git status to see the state of things, git add <modified files>, and the git commit - you should either see an error or files will be committed.

xcode commit missing file or directory

I'm not sure what happen but when I try to commit my changes in Xcode I get an
fatal: Could not switch to '/Users/charlesbutler/xCode/MA Mobile/MA MobileTests': No such file or directory
I have a bunch of files like this.
Is there anything I can do to remove them from being committed. A lot of them were deleted (probably manually in the project folder by me)
This just happened to me. I had deleted a folder with contents from the project folder. Xcode didn't handle that well.
What worked to fix it was to recreate an empty folder with the same name. No need to recreate its contents.
In your case I think you just need to create a new empty "MA Mobile" folder in the same location the old one was. Then commit. It worked for me.
After the first commit I deleted the new folder, then committed again. It seems that Xcode is missing the logic to handle the deletion of a whole folder with contents.
If you'd like to simply commit all changes you made, doing so through the Terminal should fix the problem.
Open the Terminal App and cd into your project directory, once there type in the following command:
git commit -a
Enter your commit message by pressing 'i' and typing it in, then press 'Esc', then ':', and type 'wq'
All done, you're problem should be fixed.
Jader Feijo's answer solve my problem.
Just want to suggest an easier way to add comment, without all this additional Vi steps, by simply adding -m parameter:
git commit -a -m "Commit Message"
Assuming that you are using GIT - run the following in your command line;
cd "/Users/charlesbutler/xCode/MA Mobile"
git rm -r "MA MobileTests"
I had this problem after adding and then deleting sub-projects in a project that was under source control.
I fixed it by using the GitX application, selecting the Commit View, un-staging the now non existent files from the Staged Changes list, and then selecting Discard Changes for the same files in the Unstaged Changes list.
I then had to delete the repository from the Xcode Organiser-Repositories screen and restart Xcode before things were working ok again. Xcode automatically re-adds the repository back in when the project is re-opened.
Perhaps someone with GIT expertise can provide a command line alternative that performs a "Discard all changes that are no longer present on disk" action
I've had this problem because somehow a folder of the project was added to .gitignore, I removed it from there and committed the missing files. Xcode did not show me that the folder was in gitignore or that he was different from the other folders in any way.

Resources