Simple Version:
If I have a branch \"foo-555\", with a bunch of commits with messages like:
Write a script to remove lines with Redmine #555:
#!/bin/sh
mv $1 $1.$$
grep -v 'Redmine #555' < $1.$$ > $1
rm -f $1.$$
Of course you can do that however you want (eg echo a script of commands to ed).
Then launch your rebase with EDITOR set to your script:
EDITOR=/path/to/script git rebase -i REVISION
Of course it still won't be guaranteed to complete -- there may be errors during the rebase caused by leaving out revisions. You can still fix them and git rebase --continue manually.
Here's a fast solution that uses filter-branch instead of rebasing. There's no interactivity or needing to resolve conflicts.
git filter-branch --commit-filter '
if [ `git rev-list --all --grep "<log-pattern>" | grep -c "$GIT_COMMIT"` -gt 0 ]
then
skip_commit "$@";
else
git commit-tree "$@";
fi' HEAD
You'll probably want to then clean up with:
git reflog expire --expire=now
git gc --prune=now