Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

I want to change the author of one specific commit in history. It's not the last commit. I identify the commit by hash or short-hash.

1 Answer

0 votes
by (27.5k points)

Let us say, XXXXXX is the commit whose author we are trying to replace, and YYYYYY is the commit with the new author.

Step 1: Checkout the commit we are trying to modify.

$ git checkout XXXXXX

Step 2: Make the author change.

git commit --amend --author "New Author Name <New Author Email>"

Now we have a new commit with hash assumed to be YYYYYY.

Step 3: Checkout the original branch.

Step 4: Replace the old commit with the new one locally.

$ git replace XXXXXX YYYYYY

Step 5: Rewrite all future commits based on the replacement.

$ git filter-branch -- --all

Step 6: Remove the replacement for cleanliness.

$ git replace -d XXXXXX

Step 7: Push the new history (only use --force if the below fails, and only after sanity checking with git log and/or git diff).

$ git push --force-with-lease

Alternate Step: Instead of 4-6 you can just rebase onto new commit:

$ git rebase -i YYYYYY

Browse Categories