簡體   English   中英

你能把git log log regex匹配組放在git pretty輸出中嗎?

[英]Can you put the git log log regex matching group in the git pretty output?

假設我有以下查詢:

git log -100 -i --grep="^\[.*JIRA.*\]"

這假設git注釋類似

"[JIRA1234] Adding the graph to the customer balance page"

然后我想格式化輸出以顯示匹配組,例如[JIRA1234]

現在我想我應該可以這樣做:

git log -100 -i --grep="^\[.*JIRA.*\]" --pretty="%1"

但這不起作用。

另一種方法是通過管道輸入grep

git log -100 -i --grep="^\[.*JIRA.*\]" --pretty=oneline | grep -o '\[.*JIRA.*'

但是你失去了使用git log --pretty輸出添加作者姓名和其他技巧的能力。

我的問題是: 你能把git log log regex匹配組放在git pretty輸出中嗎?

我找不到任何直接的方法來處理這個請求。 如果模式"^\\[.*JIRA.*\\]"在提交日志消息中僅出現一次,則此命令可以幫助:

git log -100 -i --grep="^\[.*JIRA.*\]" --pretty=%H | while read line
do 
  p=$(git log -1 $line --pretty=%B | grep -i -o -e "^\[.*JIRA.*\]")
  git log -1 $line --pretty="$p %h %an %cn foo bar"
done

如果模式多次發生,則需要一些額外的命令,例如head -1while循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM