This will run in both bash and git bash:
git log --author="First Last" --oneline --grep=PRJ --pretty=format:"%s" | sort | cut --delimiter='-' --fields=2 | uniq
So, creating the first section posted in the question, the following is added:
| cut --delimiter='-' --fields=2 | uniq
this channel sorts the output into cut , which extracts the second field, separated by a hyphen “-”, and the result then passes to the uniq pipe to display various values.
This solution has a weakness in the form of the delimiter used for cut - if the format of the log message changes, then it may break. The best solution would be to use a regular expression search (instead of cut ) for the problem key ("/PRJ-.+\s/", I think ...) and output the part of the number.
EDIT
So, after a little digging, you can do it more reliably using grep to find the key of the element ( PRJ in this case):
git log ... | grep -oP --regexp="PRJ-\K\d+" | uniq
-o tells grep to print only the matched part of the string
-P uses PCRE (perl / PHP) regex flavor, which allows us to use \K , which eliminates the preceding matches (to this point)
Raad source share