3

I have a git commit template as below:

[overtype with subject line up to 50 chars ----->]

[overtype with details of what's in the commit]

[other information]
Ticket-Refs: 

I would like to append the string after "Ticket-Refs:" to a git log graph --pretty=format:

I was trying to use the --grep= to achieve this on the %b or %B, any help would be appreciated.

Cellze
  • 447
  • 6
  • 16

2 Answers2

1

I know I am not giving an exact answer, but if you can move the ticket-refs part to git notes, that is add notes to the commits using something like below:

git notes add sha -m "Ticket-refs:blah"

then you can easily do the graph log like you want:

git log --graph --format="%N"

Otherwise, I am not sure if it is possible to extract that part alone and then use it with the graph.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I looked at that but I would like to try and contain it all in the git commit message, would it work without the graph? – Cellze Jul 11 '11 at 16:55
  • @Cellze What do you mean without the graph? If you mean if you get the notes in the log, yes, normal `git log` shows notes along with other commit info. – manojlds Jul 11 '11 at 16:56
  • you referred to not being able to use it with the graph - I was just asking if the graph attribute was the problem. Im not looking to migrate the repo to using notes, but thanks for the answer definitely should of looked to use this from the get go. – Cellze Jul 12 '11 at 12:14
1

Definitely not the most graceful way, but here is an option:

$ git log --graph --grep=Ticket-Refs --pretty=format:'DELIMITER_STRING%B' | grep '\*.*DELIMITER_STRING\|Ticket' | sed s/DELIMITER_STRING.*//

Or another option

$ git log --graph --grep=Ticket-Refs --pretty=format:'DELIMITER_STRING%b' | grep '\*.*DELIMITER_STRING\|Ticket-Refs' | sed ':a;N;$!ba;s/DELIMITER_STRING.*Ticket-Refs://'

I shamelessly stole some of the code for the second option from another post

Community
  • 1
  • 1
Andy
  • 44,610
  • 13
  • 70
  • 69