Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Last active January 9, 2019 18:24
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmacaulay/582757 to your computer and use it in GitHub Desktop.
Save jamesmacaulay/582757 to your computer and use it in GitHub Desktop.
# git-freeze: take the current index and working tree state and "freeze" them
# by creating a commit for each as necessary
#
# git-thaw: look for commits created by git-freeze and restore them to
# working tree or index as appropriate
# alias gf='git-freeze'
# alias gt='git-thaw'
function git-freeze () {
local count=0
if git commit -m "WIP [STAGED]" > /dev/null
then
let count+=1
fi
git add --all .
if git commit -am "WIP [UNSTAGED]" > /dev/null
then
let count+=1
fi
if [ $count -eq 0 ]
then
echo "nothing committed"
else
git log -n$count --pretty=format:'%Cgreen%h %Cred%an%Creset: %s'
fi
}
function git-thaw () {
if git rev-list HEAD -n1 --pretty="format:%s" | tail -n1 | grep "^WIP \[UNSTAGED\]$" > /dev/null
then
git reset HEAD^ > /dev/null
fi
if git rev-list HEAD -n1 --pretty="format:%s" | tail -n1 | grep "^WIP \[STAGED\]$" > /dev/null
then
git reset --soft HEAD^ > /dev/null
fi
git status --short
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment