Simple Version:
If I have a branch "foo-555", with a bunch of commits with messages like:
- foo 555: blah
- foo 123: blah blah
- foo 555: blah blah blah
- foo 321: blahblah
and I want to remove all the commits that don't start with "foo 555:", is there any way to do that using git filter-branch (or any other tool for that matter)?
Original Version (More Detailed):
In our repository we have a convention where every commit message starts with a certain pattern:
Redmine #555: SOME_MESSAGE
We also do a bit of rebasing to bring in the potential release branch's changes to a specific issue's branch. In other words, I might have branch "foo-555", but before I merge it in to branch "pre-release" I need to get any commits that pre-release has that foo-555 doesn't (so that foo-555 can fast-forward merge in to pre-release).
However, because pre-release sometimes changes, we sometimes wind up with situations where you bring in a commit from pre-release, but then that commit later gets removed from pre-release. It's easy to identify commits that came from pre-release, because the number from their commit message won't match the branch number; for instance, if I see "Redmine #123: ..." in my foo-555 branch, I know that its not a commit from my branch.
So now the question: I'd like to remove all of the commits that "don't belong" to a branch; in other words, any commit that:
- Is in my foo-555 branch, but not in the pre-release branch (pre-release..foo-555)
- Has a commit message that doesn't start with "Redmine #555"
but of course "555" will vary from branch to branch. Is there any way to use filter-branch (or any other tool) to accomplish this? Currently the only way I can see to do it is to do go an interactive rebase ("git rebase -i") and manually remove all the "bad" commits.