Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Changing the Author Name for a Git or Gerrit Commit

DZone's Guide to

Changing the Author Name for a Git or Gerrit Commit

How to get around a failed commit due to a merge with remote repository and local code changes.

· Agile Zone ·
Free Resource

The Agile Zone is brought to you in partnership with Techtown Training. Learn how DevOps and SAFe® can be used either separately or in unison as a way to make your organization more efficient, more effective, and more successful in our SAFe® vs DevOps eBook.

So this was my second time having some adventure with gerrit for OpenDaylight (also read about the first time, if you are curious). This time, I pulled the remote changes and tried to commit my new changes by adding my changes. This created a merge as the commit from the remote repository and my local commits merged in a single pull request, and hence my commit failed with the below message.

$ git review

You are about to submit multiple commits. This is expected if you are
submitting a commit that is dependent on one or more in-review
commits. Otherwise you should consider squashing your changes into one
commit before submitting.

The outstanding commits are:

fe17631 (HEAD, master) Fix bug 4535/4541
475fae6 Use odlparent-lite as artifacts parent

Do you really want to submit the above commits?
Type 'yes' to confirm, other to cancel: yes
remote: Processing changes: refs: 1, done    
To ssh://pradeeban@git.opendaylight.org:29418/messaging4transport.git
 ! [remote rejected] HEAD -> refs/publish/master/bug/4535 (you are not allowed to upload merges)
error: failed to push some refs to 'ssh://pradeeban@git.opendaylight.org:29418/messaging4transport.git'


Now,

$ git statusOn branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

So it indeed shows as 2 commits - one mine, and the one pulled from the remote repository.

I had to rebase to the master to fix this.

$  git rebase origin/master

However, this left my commit attributed to the author of the previous commit, in the commit log when I try to git review.

I had to amend the author to finally fix the commit message successfully git review following that.

$ git commit --amend --author "FirstName LastName"


Adopting a DevOps practice starts with understanding where you are in the implementation journey. Download the DevOps Transformation Roadmap, brought to you in partnership with Techtown Training

Topics:
git

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}