0

I want to rewrite all of my commit messages in a repository. The repository is large and has over 10k commits. I want to replace all text that matches one of the following patterns with Issue

"(?i)conn-\d{1,4}[abcdi]"
"(?i)conn-\d{1,4}"
"(?i)connect-\d{1,4}"
"(?i)gateway-\d{1,4}[ab]"
"(?i)gateway-\d{1,4}"

I attempted to use the top answer to "What's the fastest way to edit hundreds of Git commit messages?" But using git format-patch -10000 then editing all the patches then doing git am *.patch I get tons of errors error: file/name.txt does not not exist in index the file/name.txt.

I know I can do it with git filter-branch -f --msg-filter "sed 's/<old>/<new>/'" But how can I do it with all the patterns in one go rather than one time for each pattern? Each time I execute git filter-branch the process takes 1 hour. So I would ideally just execute it one time.

Community
  • 1
  • 1
Whitecat
  • 3,882
  • 7
  • 48
  • 78
  • You can easily match multiple patterns in `sed`; if you want to use these Perl regexes (which are not supported by any `sed` dialect out of the box), execution will probably be somewhat slower, but `perl -pe 's/conn-\d{1,4}[abcdi]?|connect-\d{1,4}|gateway-\d{1,4}[ab]?/Issue/i'` would do that. – tripleee Oct 04 '16 at 01:15
  • 2
    Or if it gets too complicated, surely you can do `git filter-branch -f --msg-filter /path/to/filter_script.sh` then in filter_script.sh you can read stdin, modify it as you want, and echo it out. – Mort Oct 04 '16 at 01:16
  • 1
    See also http://stackoverflow.com/questions/7657647/combining-2-sed-commands – tripleee Oct 04 '16 at 01:17
  • @Mort is there a stack over flow question that answers how to create a script with stdin? – Whitecat Oct 04 '16 at 05:04

0 Answers0