How to change the commit author for one specific commit?

后端 未结 19 2211
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 05:15

I want to change the author of one specific commit in the history. It\'s not the last commit.

I know about this question - How do I change the author of a commit in

19条回答
  •  眼角桃花
    2020-11-22 05:38

    Github documentation contains a script that replaces the committer info for all commits in a branch.

    • Run the following script from terminal after changing the variable values

      #!/bin/sh
      
      git filter-branch --env-filter '
      
      OLD_EMAIL="your-old-email@example.com"
      CORRECT_NAME="Your Correct Name"
      CORRECT_EMAIL="your-correct-email@example.com"
      
      if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
      then
          export GIT_COMMITTER_NAME="$CORRECT_NAME"
          export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
      fi
      if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
      then
          export GIT_AUTHOR_NAME="$CORRECT_NAME"
          export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
      fi
      ' --tag-name-filter cat -- --branches --tags
      
    • Push the corrected history to GitHub:

      git push --force --tags origin 'refs/heads/*'
      

      OR if you like to push selected references of the branches then use

      git push --force --tags origin 'refs/heads/develop'
      

提交回复
热议问题