Skip to content

Instantly share code, notes, and snippets.

@oreoshake
Created June 15, 2017 22:00
Show Gist options
  • Save oreoshake/0e8de9f8bb535dbdd06eaae27297cb77 to your computer and use it in GitHub Desktop.
Save oreoshake/0e8de9f8bb535dbdd06eaae27297cb77 to your computer and use it in GitHub Desktop.
Automatically restore your working state from the last time you pulled a `git commit -am "wip"`
#!/bin/bash
set -e
prevHEAD=$1
newHEAD=$2
checkoutType=$3
[[ $checkoutType == 1 ]] && checkoutType='branch' ||
checkoutType='file' ;
if [ $checkoutType == 'branch' ]; then
clean=`git status --porcelain`
if [ -z "$clean" ]; then
wip=`git log --oneline -n 1 | cut -d" " -f2`
if [ $wip == "wip" ]; then
echo "WIP commit found, rolling back"
git reset HEAD^
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment