How to amend several commits in Git to change author

前端 未结 6 1004
逝去的感伤
逝去的感伤 2020-11-28 17:14

I have made a series of commits in Git and I realise now that I forgot to set my user name and user email properties correctly (new machine). I have not yet pushed these co

6条回答
  •  醉梦人生
    2020-11-28 17:46

    Rebase/amend seems inefficient, when you have the power of filter-branch at your fingertips:

    git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "incorrect@email" ]; then
         GIT_AUTHOR_EMAIL=correct@email;
         GIT_AUTHOR_NAME="Correct Name";
         GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
         GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all
    

    (split across lines for clarity, but not necessary)

    Be sure to inspect the result when you're done, to make sure that you didn't change anything you didn't mean to!

提交回复
热议问题