需求
将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
- 对于bash,双引号里面的字符会被解释,单引号不会,所以这里sed必须被双引号引用,否则${c}无法被引用
- 关于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.
网友评论