Skip to content

Instantly share code, notes, and snippets.

@uasi
Created September 6, 2014 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uasi/9ec5d2d7fdea7a49567e to your computer and use it in GitHub Desktop.
Save uasi/9ec5d2d7fdea7a49567e to your computer and use it in GitHub Desktop.
git-patchbox
#!/bin/sh
#
# git-patchbox
#
# Saves a series of patches from the given revision to HEAD as
# <toplevel>/,patchbox/<name>.mbox and then reset to the revision.
#
if [ "x$1" = "x" -o "x$2" = "x" ]; then
echo "usage: git-patchbox <revision> <mbox name>"
exit 1
fi
revision=$1
mbox_name=${2}.mbox
if [ "${revision#*..}" != "$revision" ]; then
echo "fatal: revision must not be a range"
exit 1
fi
git_dir=`git rev-parse --git-dir`
[ -d "$git_dir" ] || exit 1
patchbox=`git rev-parse --show-toplevel`/,patchbox
if [ -e "$patchbox/$mbox_name" ]; then
echo "fatal: mbox already exists"
exit 1
fi
mkdir -p "$patchbox"
set -e
set -x
git format-patch --stdout "$revision" > "$patchbox/$mbox_name"
git reset --hard "$revision"
@uasi
Copy link
Author

uasi commented Sep 6, 2014

# Example

$ git patchbox HEAD^^ apply-me-later
+ git format-patch --stdout 'HEAD^^'
+ git reset --hard 'HEAD^^'
HEAD is now at deadbeef Hoge

$ ls ,patchbox
apply-me-later.mbox

$ git am ,patchbox/apply-me-later.mbox
...

.gitignore に ,*/ 書いとくと便利

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment