Search code examples
xcodegit

Xcode project shows two git repositories (only one is correct); commits go to both


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.

XCode UI showing Scheduler project

New Project 2 ("Scheduler6"): Shows two repositories, and the last commit I did there shows up in both.

XCode UI showing Scheduler and Scheduler6 projects

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.)


Solution

  • 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.)

    1. Duplicate Project_2.xcodeproj (which is actually a bundle).

    2. 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").

    3. Launch Terminal.

    4. 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/
    
    1. 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 = ""; };

    1. 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.

    2. Check that the GIT navigator only shows Project 2. You might have to close Xcode and relaunch.