Skip to main content
added 225 characters in body
Source Link
bxm
  • 5.2k
  • 1
  • 22
  • 26

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ {print $2"-"$3":"$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" 

Everything that isn't alpha or numeric is a field delimiter

$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ 

In cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue

{print $2"-"$3":"$1} 

Print the first 3 fields in the desired order.


More robust alternative, based heavily on Ed Morton's answer (adapted lightly for the simpler custom log format):

git log --pretty=format:'%H %s' \ | awk -v OFS=: \ ' match($2, /^[[:upper:]]+-[[:digit:]]+/) { print(substr($2, 1, RLENGTH), $1) } ' 

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ {print $2"-"$3":"$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" 

Everything that isn't alpha or numeric is a field delimiter

$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ 

In cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue

{print $2"-"$3":"$1} 

Print the first 3 fields in the desired order.

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ {print $2"-"$3":"$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" 

Everything that isn't alpha or numeric is a field delimiter

$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ 

In cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue

{print $2"-"$3":"$1} 

Print the first 3 fields in the desired order.


More robust alternative, based heavily on Ed Morton's answer (adapted lightly for the simpler custom log format):

git log --pretty=format:'%H %s' \ | awk -v OFS=: \ ' match($2, /^[[:upper:]]+-[[:digit:]]+/) { print(substr($2, 1, RLENGTH), $1) } ' 
added 17 characters in body
Source Link
bxm
  • 5.2k
  • 1
  • 22
  • 26

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+9]+$/ {print $2"-"$3,$1"$3":"$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" # everything that isn't alpha or numeric is a field delimiter  

Everything that isn't alpha or numeric is a field delimiter

$2"-"$3 ~ /^[A-Z]+-[0-9]+9]+$/ # in cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue  

In cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue

{print $2"-"$3,$1"$3":"$1} # print the first 3 fields in the desired order.  

Print the first 3 fields in the desired order.

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+/ {print $2"-"$3,$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" # everything that isn't alpha or numeric is a field delimiter  $2"-"$3 ~ /^[A-Z]+-[0-9]+/ # in cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue  {print $2"-"$3,$1} # print the first 3 fields in the desired order.  

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ {print $2"-"$3":"$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" 

Everything that isn't alpha or numeric is a field delimiter

$2"-"$3 ~ /^[A-Z]+-[0-9]+$/ 

In cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue

{print $2"-"$3":"$1} 

Print the first 3 fields in the desired order.

Source Link
bxm
  • 5.2k
  • 1
  • 22
  • 26

I wouldn't process the "default" log, ever.

You can get halfway there just with a different log format. In this case printing the Hash and Commit message only.

git log --pretty=format:'%H %s' 

And then use awk to finish up (making the assumption that ticket refs appear at the start of the commit message)

git log --pretty=format:'%H %s' | \ awk -F"[^a-zA-Z0-9]" '$2"-"$3 ~ /^[A-Z]+-[0-9]+/ {print $2"-"$3,$1}' 

Explaining that awk:

-F"[^a-zA-Z0-9]" # everything that isn't alpha or numeric is a field delimiter $2"-"$3 ~ /^[A-Z]+-[0-9]+/ # in cases where field 2 and 3 (first two "words" of the commit message) look like they are probably a ticket ref, we continue {print $2"-"$3,$1} # print the first 3 fields in the desired order.