Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created August 5, 2011 11:11
Show Gist options
  • Save yuroyoro/1127324 to your computer and use it in GitHub Desktop.
Save yuroyoro/1127324 to your computer and use it in GitHub Desktop.
git back でひとつ前に居たbranchに戻る
#!/bin/sh
# usage:
# git back でひとつ前に居たbranchに戻る
# git back N でN個前に戻る
# git back --listで履歴だす
#
# /usr/local/libexec/git-coreに置いてchmod +xしとけ
CNT=1
if [ $# -ne 0 ]; then
if [ $1 = "--list" ]; then
git reflog | grep checkout | head -10 | cut -d' ' -f6
exit
else
CNT=$1
fi
fi
PREVIOUS_BRANCH=`git reflog | grep checkout | head -${CNT} | tail -1 | cut -d' ' -f6`
git checkout ${PREVIOUS_BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment