Skip to content

Instantly share code, notes, and snippets.

@jburwell
Last active December 18, 2015 10:49
Show Gist options
  • Save jburwell/5771480 to your computer and use it in GitHub Desktop.
Save jburwell/5771480 to your computer and use it in GitHub Desktop.
Creates a squashed patch from a Git feature branch. This example was used create he S3-backed Secondary Storage patch for CloudStack This script does not rebase/merge with the REF_BRANCH upstream. It is expected these operations will be performed as needed before this script is executed.
#!/bin/bash
WORK_HOME=/Users/jburwell/Documents/projects/cloudstack/src/cloudstack-basho
REF_BRANCH=master
FEATURE_BRANCH=s3-secondarystorage
WORK_BRANCH="$FEATURE_BRANCH-prep"
PATCH_FILE=$1
COMMIT_MSG=$2
if [ -z $PATCH_FILE ]; then
echo "A patch file name must be specified."
return 1
fi
if [ -z $COMMIT_MSG ]; then
echo "A commit message must be specified."
return 1
fi
cd $WORK_HOME
echo "Checking out reference branch, $REF_BRANCH"
git checkout $REF_BRANCH
echo "Destroying work branch, $WORK_BRANCH"
git branch -D $WORK_BRANCH
echo "Creating a fresh work branch, $WORK_BRANCH"
git checkout -b $WORK_BRANCH
echo "Perform a squashed merge on $WORK_BRANCH from $FEATURE_BRANCH"
git merge --squash $FEATURE_BRANCH
echo "Committing the merge with message $COMMIT_MSG"
git commit -am $COMMIT_MSG
echo "Create the patch from $WORK_BRANCH as $1"
git format-patch $REF_BRANCH --stdout > $1
echo "Switch back to feature branch, $FEATURE_BRANCH"
git checkout $FEATURE_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment