Skip to content

Instantly share code, notes, and snippets.

@tomwadley
Created September 6, 2013 15:08
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 tomwadley/6465147 to your computer and use it in GitHub Desktop.
Save tomwadley/6465147 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Call with a branch name to merge it and then reset backwards leaving
# all the changes from that branch in the working tree for ease of reviewing.
# The script assumes you are already on the branch you are merging to
# (e.g. master) and have updated your remotes.
# Once you're happy, pass "commit" to reset forwards again.
do_git_review() {
if git diff-index --quiet HEAD --; then
git merge --no-ff $1
git reset --soft HEAD^
else
echo "Can't do that - working tree has changes"
fi
}
do_git_commit() {
git reset HEAD@{1}
}
if [ $# -eq 0 -o "$1" == "-h" -o "$1" == "--help" ]; then
echo "usage: $0 <branch>"
echo " or: $0 commit"
exit 1
fi
if [ "$1" == "commit" ]; then
do_git_commit
else
do_git_review $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment