美文网首页
如何用filter-branch批量修改commit messa

如何用filter-branch批量修改commit messa

作者: goodcwj | 来源:发表于2020-06-09 10:57 被阅读0次

    需求

    将1百多个git commit的commit message中的JIRA ID替换成对应的branch的JIRA ID.

    方案

    #!/bin/bash -x
    a=("JIRA-48723" "JIRA-49376")
    b=("JIRA-72232" "JIRA-72233")
    len=${#a[@]}
    for (( i=0; i<${len}; i++ ))
    do
      echo ${a[$i]}
      echo ${b[$i]}
      c="s/${a[$i]}/${b[$i]}/g"
      git filter-branch -f --msg-filter "sed \"${c}\"" 630_p..HEAD
    done
    
    1. 对于bash,双引号里面的字符会被解释,单引号不会,所以这里sed必须被双引号引用,否则${c}无法被引用
    2. 关于Filter-branch使用方法
      https://git-scm.com/docs/git-filter-branch/2.2.3

    --msg-filter <command>
    This is the filter for rewriting the commit messages. The argument is evaluated in the shell with the original commit message on standard input; its standard output is used as the new commit message.

    相关文章

      网友评论

          本文标题:如何用filter-branch批量修改commit messa

          本文链接:https://www.haomeiwen.com/subject/dxqstktx.html