Running filter-branch over a range of commits

The cleanest solution I found was to do the following:

  1. Create a temporary branch at refb.
  2. Apply the branch filter on refa..temp.
  3. Rebase onto the temporary branch and delete it.

ie.

git branch temp refb

git filter-branch --env-filter '
export GIT_AUTHOR_EMAIL="[email protected]"' refa..temp

git rebase temp
git branch --delete temp

You cannot apply the filter-branch in the middle of the history, as said by @kan. You must apply from your known commit to the end of the history

git filter-branch --env-filter '...' SHA1..HEAD

Filter-branch can check for the commit author or other information, to chose to change or not the commit, so there are ways to accomplish what you want, see https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History, look for "Changing Email Addresses Globally"

Remember: if you have pushed the commits to a public repository you should not user filter-branch