Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function gch() {
  2. local currentBranch=$(git rev-parse --abbrev-ref HEAD)
  3. local previousFile="$(git rev-parse --show-toplevel)/.git/PREVIOUS_HEAD"
  4. if [ -n "$1" ]; then
  5. echo "$currentBranch" >> $previousFile
  6. git checkout "$@"
  7. else
  8. if [ ! -f "$previousFile" ]; then echo >&2 "ERROR: Missing PREVIOUS_HEAD. Please run gch with 1 argument first."
  9. else
  10. git checkout "$(cat $previousFile | tail --lines=1)"
  11. echo "$currentBranch" >> $previousFile
  12. fi
  13. fi
  14. # truncate the file
  15. tail -n10 $previousFile > "$previousFile.TEMP"
  16. mv -f "$previousFile"{.TEMP,}
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement