Skip to content

Instantly share code, notes, and snippets.

@guilhermejcgois
Last active August 2, 2022 01:57
Show Gist options
  • Save guilhermejcgois/8a6be42fc382f24201ab66602479ce80 to your computer and use it in GitHub Desktop.
Save guilhermejcgois/8a6be42fc382f24201ab66602479ce80 to your computer and use it in GitHub Desktop.
Getting all scopes from commits summary in a repo for commitizen friendly repos
git log --pretty="%s" | grep -o -P '(?<=\().*(?=\))' | grep -v -F 'pull request' | uniq
@lgersman
Copy link

Thanks - this was a great starting point for me !

I use that snippet to provide commitizen commit suggestions for the scope in a custom tui app for git-cz with a few additions/changes :

  • on my system (Linux/Bash) the last command uniq didn't worked es expected until I sort'ed the scopes before the uniq call

  • I used to use also a filter using sed to suppress matches from malformed commit messages containing : , ( or )

So I ended up with

git log --pretty="%s" | grep -o -P '(?<=\().*(?=\))' | grep -v -F 'pull request' | sed '/[:()]/d' | sort | uniq

@guilhermejcgois
Copy link
Author

Glad to help! Will update my local alias with your tip, thank you to share back to me. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment