Running filter-branch over a range of commits

前端 未结 8 1341
夕颜
夕颜 2020-12-02 14:26
git filter-branch --env-filter \'
export GIT_AUTHOR_EMAIL=\"foo@example.com\"
export GIT_AUTHOR_NAME=\"foo\"\' -- commita..commitb

Results in

8条回答
  •  情书的邮戳
    2020-12-02 14:46

    Enclose you filter commands in an if-statement that checks for that range. You can check whether a commit is within a given range with this command:

    git rev-list start..end | grep **fullsha**
    

    The current commit will be stored in $GIT_COMMIT in your filter. So your filter becomes:

    git filter-branch --env-filter '
      if git rev-list commita..commitb | grep $GIT_COMMIT; then
        export GIT_AUTHOR_EMAIL="foo@example.com"
        export GIT_AUTHOR_NAME="foo"
      fi' -- ^commita --all
    

    If you want to only rewrite your current branch, replace --all with HEAD

提交回复
热议问题