Search code examples
gitgit-merge

Using git to merge changes in a manually-copied directory


At work I keep a backup of a large directory on our remote VPS using git. Because I live in a very remote town with poor, expensive internet, I cannot copy this repo over the internet. Instead, when I started working from home, I brought a copy of the directory on an external drive (unfortunately without the ".git" subdirectory).

I have made about 10kb worth of changes to files in my home copy of the directory. I would like to merge these in to the git repo on the remote server without transferring the whole directory over the internet.

Steps so far:

git init
git add .
git commit -m "initial"
git remote add VPS [SSH_ADDRESS]
git remote show VPS   # successfully connects to remote

Now I'd like to merge the 10kb of changes I've made locally without transferring the GB of data that are unchanged.

Steps I've tried but failed:

git push VPS   # can't because there are non-integrated remote changes
git fetch VPS  # starts downloading GBs of data

Not sure where to go next.


Solution

  • A hacky approach that tries to transfer as little data as possible, not using git's transport methods, that may or may not work:

    • generate patches of your local work (git format-patch)
    • compress those patches (tar or zip)
    • send them to to the remote server (scp or rsync)
    • login to the remote server (ssh)
    • apply the patches (unzip/tar followed by git apply), fix conflicts and edit the history to your liking

    This will leave your local copy out of sync, as before.


    Assuming that the "GBs of data" are large files and not many small changes/files, you can circumvent having to store them in the actual git repo.

    There are multiple approaches to this problem, of which I have tried neither, but here are some pretty well known: