How to change the author and committer name and e-mail of multiple commits in Git?

后端 未结 30 3047
野性不改
野性不改 2020-11-21 04:50

I was writing a simple script in the school computer, and committing the changes to Git (in a repo that was in my pendrive, cloned from my computer at home). After several c

30条回答
  •  粉色の甜心
    2020-11-21 05:17

    1. Change commit author name & email by Amend, then replacing old-commit with new-one:

      $ git checkout                             # checkout to the commit need to modify  
      $ git commit --amend --author "name " # change the author name and email
      
      $ git replace        # replace the old commit by new one
      $ git filter-branch -- --all                           # rewrite all futures commits based on the replacement                   
      
      $ git replace -d      # remove the replacement for cleanliness 
      $ git push -f origin HEAD              # force push 
      
    2. Another way Rebasing:

      $ git rebase -i       # back to last good commit
      
      # Editor would open, replace 'pick' with 'edit' before the commit want to change author
      
      $ git commit --amend --author="author name "  # change the author name & email
      
      # Save changes and exit the editor
      
      $ git rebase --continue                # finish the rebase
      

提交回复
热议问题