top | item 36633460

(no title)

fantapop | 2 years ago

Here are a couple that I use a lot. There's probably a shorter way to write them:

  # show the last 10 branches I used
  lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\"  \\033[33m%s: \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'

  # checkout the previous branch I was using
  cop = !git checkout --recurse-submodules $(git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | grep -v $(git branch --show-current) | head -1 | cut -d' ' -f1)

discuss

order

MattBearman|2 years ago

Unless I’m misunderstanding you can checkout your previous branch with

  git checkout -
(The same way you can use ‘cd -‘ to change to your previous directory)

fantapop|2 years ago

Thank you I didn't know about this. Your version is a bit more compact.