Home > Enterprise >  Commit Author Not showing recent commiter name when doing Git Squash
Commit Author Not showing recent commiter name when doing Git Squash

Time:10-14

I have a branch and few commits done by some other person. I committed few more changes to the same branch. Now i am squashing all commits to one single commit using below commands.

git rebase -i HEAD~2

From the displayed commit list changed the first commit from pick to reword second one from pick to squash then modified the commit message to some meaningful msg git push --force

Now when i see on the remote the author/committer name is still showing the old author name. Is there a way i can have this name changed to mine as i am the recent committer?

CodePudding user response:

The easiest way to do that is by amending the squashed commit with the --reset-author option:

When used with -C/-c/--amend options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.

In your case, you can simply do this after you've squashed all the commits into one:

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

This will set the current user.name and user.email as the author of the commit.

CodePudding user response:

To rewrite the author of the last commit , run git commit --amend --no-edit --reset-author after git rebase is done.

If you want to rewrite all rebased commits, append the option --exec 'git commit --amend --reset-author --no-edit' to git rebase.

git rebase -i head~2 --exec 'git commit --amend --reset-author --no-edit'

The todo list will be expanded as

pick 001111 foo
exec git commit --amend --reset-author --no-edit
pick 002222 bar
exec git commit --amend --reset-author --no-edit

If you want to rewrite some of the rebased commits, manually add exec git commit --amend --reset-author --no-edit below the commit entry you want. For example,

pick 001111 foo
pick 002222 bar
exec git commit --amend --reset-author --no-edit
pick 003333 baz
  • Related