Running filter-branch over a range of commits

前端 未结 8 1299
夕颜
夕颜 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:58

    git filter-branch does accept range notation, but the end of the range needs to be a reference, not the ID of a commit.

    git checkout -b tofilter commitb
    git filter-branch .... commita..tofilter
    

    If given just commits, it would not know what ref to update with the filtered branch.

    0 讨论(0)
  • 2020-12-02 15:04

    You cannot just override commits in a middle of a history, because sha1 of a commit depends on a parent's. So, the git doesn't know where do you want point your HEAD reference after the filtration. So, you should rewrite all up to the HEAD.

    Example:

    A---B---C---D---E---F   master
                \
                 \--G---H   branch
    

    if you want filter commits B and C you should also filter all commits after: D, E, F, G, H. So, that's why git tells you to use a ref at the end of the range, so that it just not finishes up with a detached head.

    After you modify B and C commits and stop will look like this:

    A---B---C---D---E---F   master
    \           \
     \           \--G---H   branch
      \-B'--C'      (HEAD or a temporary TAG?..)      
    

    So, the master and branch will be untouched. I don' think this is that you want. It means you must override all commits. The history will be then:

    A---B---C---D---E---F   (loose end, will be garbage collected one day)
    \           \
     \           \--G---H   (loose end, will be garbage collected one day)
      \-B'--C'--D'--E'--F'  master
                \
                 \--G'--H'  branch
    
    0 讨论(0)
提交回复
热议问题