Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gch() {
- local currentBranch=$(git rev-parse --abbrev-ref HEAD)
- local previousFile="$(git rev-parse --show-toplevel)/.git/PREVIOUS_HEAD"
- if [ -n "$1" ]; then
- echo "$currentBranch" >> $previousFile
- git checkout "$@"
- else
- if [ ! -f "$previousFile" ]; then echo >&2 "ERROR: Missing PREVIOUS_HEAD. Please run gch with 1 argument first."
- else
- git checkout "$(cat $previousFile | tail --lines=1)"
- echo "$currentBranch" >> $previousFile
- fi
- fi
- # truncate the file
- tail -n10 $previousFile > "$previousFile.TEMP"
- mv -f "$previousFile"{.TEMP,}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement