Skip to content

Instantly share code, notes, and snippets.

@mandre00
Forked from favila/git-squash.sh
Created May 16, 2023 06:50
Show Gist options
  • Save mandre00/941085f15770d47dc10d8aa88ab30854 to your computer and use it in GitHub Desktop.
Save mandre00/941085f15770d47dc10d8aa88ab30854 to your computer and use it in GitHub Desktop.
git-squash: script to create a squashed patch from a branch.
#! /bin/sh
# Produce a squash-commit patch from a branch of changes
MASTER=$1
PATCHBRANCH=$2
SQUASHBRANCH="$PATCHBRANCH-squash"
MESSAGE=$3
git checkout -b $SQUASHBRANCH $MASTER &&
git merge --squash $PATCHBRANCH &&
git commit -a -m "$MESSAGE" &&
git format-patch $MASTER --stdout > $PATCHBRANCH.patch &&
git checkout $PATCHBRANCH &&
git branch -D $SQUASHBRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment