0

I am using git version control.
I've committed and pushed some changes with my first name as author name. then many authors committed and pushed our changes, but now I need to change the committed author name only not message.
Is any way to do this changes?

Sakthi Karthik
  • 3,105
  • 4
  • 25
  • 29
  • Have you pushed yet? – Berry M. Aug 03 '17 at 13:39
  • 4
    Possible duplicate of [Change commit author at one specific commit](https://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit) – Tim Biegeleisen Aug 03 '17 at 13:40
  • 1
    You have to rewrite the commit in question. If you've already pushed, then get ready for a mess, especially if others have pulled your commit already. If you _haven't_ pushed yet, then check the duplicate link for how to rewrite that commit with a different author. – Tim Biegeleisen Aug 03 '17 at 13:41

2 Answers2

1

It seems you want to change the author name for all the commit histories. You can use git filter-branch to change the author name:

git filter-branch --commit-filter '
        if [ "$GIT_AUTHOR_NAME" = "old name" ];
        then
                GIT_AUTHOR_NAME="new name";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD

It will take a few minutes to rewrite the commit history.

After that you can use git push -f --all to update the remote repo.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • WARNING: git-filter-branch has a glut of gotchas generating mangled history rewrites. Hit Ctrl-C before proceeding to abort, then use an alternative filtering tool such as 'git filter-repo' (https://github.com/newren/git-filter-repo/) instead. See the filter-branch manual page for more details; to squelch this warning, set FILTER_BRANCH_SQUELCH_WARNING=1. – arunkumaraqm May 05 '22 at 07:58
0

Assuming you haven't pushed yet:

  1. Undo the commit with git reset --soft HEAD^
  2. Change your name with git config --global user.name "Berry M."
  3. Commit your changes again.
Berry M.
  • 469
  • 1
  • 4
  • 17
  • i was committed and pushed around 100 changes – Sakthi Karthik Aug 03 '17 at 13:51
  • If you mean to tell me you've already pushed, look at https://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit as @tim-biegeleisen mentioned in the comments above. – Berry M. Aug 03 '17 at 13:59