Skip to content

Instantly share code, notes, and snippets.

@IamFaizanKhalid
Last active June 30, 2024 09:47
Show Gist options
  • Save IamFaizanKhalid/c0f0475a58a2e331735feb1dd1c7ac59 to your computer and use it in GitHub Desktop.
Save IamFaizanKhalid/c0f0475a58a2e331735feb1dd1c7ac59 to your computer and use it in GitHub Desktop.
Change author information of previous commits.

Interactive rebase off of a point earlier in the history than the commit you need to modify (git rebase -i <earliercommit>). In the list of commits being rebased, change the text from pick to edit next to the hash of the one you want to modify. Then when git prompts you to change the commit, use this:

git commit --amend --reset-author --no-edit

For example, if your commit history is A-B-C-D-E-F with F as HEAD, and you want to change the author of C and D, then you would...

  1. Update author's info git config --global user.email example@email.com
  2. Specify git rebase -i B (here is an example of what you will see after executing the git rebase -i B command)
  • if you need to edit A, use git rebase -i --root
  1. Change the lines for both C and D from pick to edit
  2. Exit the editor (for vim, this would be pressing Esc and then typing :wq).
  3. Once the rebase started, it would first pause at C
  4. You would git commit --amend --reset-author --no-edit && git rebase --continue
  5. It would pause again at D
  6. Then you would git commit --amend --reset-author --no-edit && git rebase --continue
  7. The rebase would complete.
  8. Use git push -f to update your origin with the updated commits.
@DavidChu941
Copy link

Hi! I read your script and this is amazing.
but in this case, how do i have to choose the repository for changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment