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/
- In Terminal, execute "
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.
cd /path/to/my/unique/repo; git --work-tree=/path/to/old/worktree1 add .; git commit -m "Import worktree v1"
; repeat for v2 and so on. – Objection