Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Last active September 17, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivertappin/d2e7682bfd118ac64127dad6aaf3645c to your computer and use it in GitHub Desktop.
Save olivertappin/d2e7682bfd118ac64127dad6aaf3645c to your computer and use it in GitHub Desktop.
Extract a string from a commit message between two square brackets
# Example with a space after the colon
echo "bc3977f Some beautiful long commit message [skip: verification]" | sed -En 's/.*\[skip\:(.*|\ .*)\]/\1/p' | awk '{$1=$1;print}'
verification
# Example with no space after the colon
echo "bc3977f Some beautiful long commit message [skip: verification]" | sed -En 's/.*\[skip\:(.*|\ .*)\]/\1/p' | awk '{$1=$1;print}'
verification
# Working example from the last commit message
git log -1 --oneline | sed -En 's/.*\[skip\:(.*|\ .*)\]/\1/p' | awk '{$1=$1;print}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment