1

I recently went from two people developing one project in one repo to having many developers working in one repo and we copy tested commits to the production repo.

We are often encountering git errors copying the commits from one repo to the other.

This is the script I use to copy a commit from the development repo to the production repo:

[ "$1" == "" ] && echo "must specify SHA" >&2 && exit 1

# To sync commits from dev to production
# First switch to the dev code directory:
cd /root/cg-dev
# arg is a hash of the commit you want to sync via "git log" (or other git commands)
SHA=$1 && \
  cd /root/cg && \
  git --git-dir=/root/cg-dev/.git \
  format-patch -k -1 --stdout $SHA | \
  git am -3 -k --ignore-whitespace
# Then you need to push changes to the dev server:
git push origin master

Below is a git error that we frequently have been getting when executing that script. Often the problem goes away by re-committing the code under new branches, but this takes too long. We want to fix the problem in our procedure and eliminate these. enter image description here

masterbinoy
  • 118
  • 11
  • Worth mention: Git prints the above error message when it needs to do the `-3` part of `git am`, but the `index:` line in the format-patch output cannot be matched to an existing blob. It's wise to add `--full-index` if you believe the blob should be present, or to use some method other than just `format-patch` if not. – torek Mar 12 '18 at 15:14

1 Answers1

0

Instead of trying to communicate patches, you can communicate the repo itself, compressed into one file, with git bundle.

You can make an incremental bundle (with only commits from a certain point).

From a tag:

git bundle create file.bundle lastR2bundle..master
machineA$ git tag -f lastR2bundle master

Or even from the last 10 days:

git bundle create mybundle --since=10.days master

You get one file, easy to copy around.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The problem is that the repos are not identical - only 99% identical. Some configuration files must not be copied from one to the other. – masterbinoy Mar 13 '18 at 11:42
  • @masterbinoy you can keep configuration file separate, generating the right one automatically: https://stackoverflow.com/a/39762768/6309 – VonC Mar 13 '18 at 11:52