Reputation: 2699
I'm new to git. So, I'm confused and might not be using the correct terminology.
I have two separate Xcode projects, each with it's own local repository. Although the projects have similar names, each project has separate and distinct source files. I've done a couple of commits to each, but when I commit in one project, the commit shows up in both. My new project shows both projects in the git navigator (which might be related to the problem). When I made the new commit, the old project was not open in Xcode.
Each project has it's own .git folder.
Details:
Old Project 1 ("Scheduler"): Shows one repository, but the last commit I did in the new project appears there.
New Project 2 ("Scheduler6"): Shows two repositories, and the last commit I did there shows up in both.
Why does Project 2 show both repositories, and is that the reason my commit ended up in both? How to correct that? This has happened before, and I did "git reset HEAD^" in the old repository to remove the incorrect commit. I want to stop this behavior forever. (And I'm hesitant about fooling around with git commands in Terminal.)
Upvotes: 5
Views: 1890
Reputation: 8988
None of the above worked for me as there were no file references to the other project.
What did work was deleting the derived data folder using Xcode -> Settings -> Locations
Upvotes: 0
Reputation: 91
I had the same problem, I think it happened because I Initialised git twice on one project. First when I wanted to create the project folder I executed "git init" in the terminal, and later when I wanted to create the project itself by Xcode (a swift project), I did not remove the check mark from initiate a git repo for project. So I have initiated two git repos for one project.
Upvotes: 0
Reputation: 2699
Mystery solved. I created Project 2 by copying numerous files from Project 1, but three image files ended up as references to the Project 1 files, not copies. When I removed those references and added copies instead to Project 2, the GIT navigator stopped showing the Project 1 repository.
Summary: Project 2 showed both GITs because Project 2 referenced some files in Project 1.
There are two ways to fix the trouble:
A. Manually: Open Project 2, select each file (one by one), and check that the Full Path shown in the Identity and Type inspector is a Project 2 path. Fix any files that reference Project 1.
B. Using Terminal: The Xcode project control file is a text file, so checking all Full Paths can be automated using Terminal commands, thusly:
(I assume the two projects are named Project_1 and Project_2, and that their project folders share the same parent folder.)
Duplicate Project_2.xcodeproj
(which is actually a bundle).
Change the duplicate's filename suffix from .xcodeproj
(I used .xxx
). The duplicated "file" becomes a subfolder containing four items, one of which is a text file ("project.pbxproj
").
Launch Terminal.
In Terminal, execute "cd path_to_project_2_subfolder
". Shortcut: type 'cd
', space, drag the folder that as created in step 2 to Terminal, and hit return.
x. (Verification step.) In Terminal, execute "ls
" to show the four items. They should be:
project.pbxproj project.xcworkspace/ xcshareddata/ xcuserdata/
strings project.pbxproj | grep ../Project_1/
". This shows all lines in project.pbxproj that reference Project_1. '|
' is a pipe command that sends the strings
output to grep
which filters the strings. Because my two project names differed by only one character, I surrounded the project name with '../
' and '/
' to limit the output to directories and files that belong to Project_1, but you could just use the bare project name if your two names are dis-similar. The commands and arguments are case-sensitive. You should see some lines that reference Project_1. You could also open project.pbxproj
in a text editor and search for lines containing Project_1
.One of my files (sharing.png) appeared thusly:
1F4E32C32343DE1A0053C239 /* sharing.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = sharing.png; path = ../../../../Project_1/sharing.png; sourceTree = ""; };
Open Project_2 in Xcode and fix the files that show as references in the strings command. Along the way, use Method A (above) to verify your work.
Check that the GIT navigator only shows Project 2. You might have to close Xcode and relaunch.
Upvotes: 10