Using git filter-branch to remove commits by their commit message

后端 未结 2 467
情歌与酒
情歌与酒 2020-12-15 10:57

Simple Version:

If I have a branch \"foo-555\", with a bunch of commits with messages like:

  • foo 555: blah
  • foo 123: blah blah<
2条回答
  •  青春惊慌失措
    2020-12-15 11:44

    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.

提交回复
热议问题