Home > other >  Change author information of multiple commits
Change author information of multiple commits

Time:11-04

If I have 200 commits that I have pushed with wrong author information in git config --global user.email and git config --global user.name. How can I change these commits afterwards in a command without having to go through every one of each?

All commits are of the same author and some commits are between with a different author. So is it possible to iterate over each commit FROM and TO commits and send a git push --force-with-lease command to update all of these in the history of the master branch?

Any idea?

CodePudding user response:

If they are in a straight line, you could pull it off with a little bit of bash-fu:

git checkout first-commit-to-adjust~ # careful with the pig-tail... it has to be there
git log --pretty=%h --reverse HEAD..last-one-to-adjust | while read commit; do
    git cherry-pick $commit
    # here we need a check for the author name
    if [ "$( git show --summary --pretty=%an --quiet )" == "misnamed fulanito de tal" ]; then
        # yep, it's me
        git commit --amend --no-edit --reset-author
    fi
done

If you want to only set author name/email (not modifying author date), I think you will have to set values for GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables and then issue the git commit --amend --no-edit command. Concept does not change.... and if you want to control more things, then there are more environment variables at your disposal to play with. Check git help commit.

  •  Tags:  
  • git
  • Related