Synchronize two version of the same project ?

I am trying to get a better feel for how a local git repository works in XCode 10. I started a project on my iMac with a local git repo and made lots of commits over a couple of branches. Then I coppied the project on to another mac laptop and made more changes to the project but have not committed them yet. I see on the macbook that the coppied project still has reference to all of its git info. I think the git repo is in the project folder, but I don't see it via the finder. I want to get the newer version back on my iMac which is my main development area. How should I go about that? I could commit the laptop version and then copy that to a different folder on the iMac. Should I then delete the original folder with the original project? I have an actual git hub account so I could push the laptop version up there although it has some login info that I would not want made public. I think if I understood a little more about where the local repo lives and how a project finds it, I might not be asking this question. Thanks for any advice.

Replies

You didn't really specify which version has which changes. If one is simply newer than the other one, just copy the new one back over. If you have made separate changes to each, then copy one of them to a folder adjacent to its alternate version. Do a manual:


diff -r --brief --exclude=.git "$dir1" "$dir2"


and just fix the differences.


Here is a little script that I would then run on each line of the above output that shows a change:


#!/usr/bin/perl

use strict;

my @files;
my $last;

foreach my $file (@ARGV)
  {
  next
    if $file eq 'Files';

  next
    if $file eq 'and';

  next
    if $file eq 'differ';

  if($file =~ /^".+"$/)
    {
    push @files, $file;
    }
  else
    {
    push @files, qq{"$file"};
    }

  $last = $file;
  }

# Now run opendiff with the previous version and the current version.
system(qq{opendiff @files -merge "$last" 2> /dev/null});


That last line is the key part. It runs the "opendiff" tool in merge mode so you can manually merge changes and then just save to record your changes into "$dir2".


That will get this one project fixed. In the future, you can do one of two things - preferably both:

1) Get your self a paid github account or something similar where you can have private repositories; and

2) Configure your projects so that any sensitive information can be exluded.

The local repo "lives" in a hidden folder called ".git" in the main project folder (where the .xcodeproj file is). In Sierra or later, use CMD-SHIFT-. (period) to show hidden files/folders while in Finder.


EDIT: added clarification "while in Finder".