Skip to content
Fix Code Error

How to change the author and committer name and e-mail of multiple commits in Git?

March 13, 2021 by Code Error
Posted By: Anonymous

I was writing a simple script in the school computer, and committing the changes to Git (in a repo that was in my pendrive, cloned from my computer at home). After several commits I realized I was committing stuff as the root user.

Is there any way to change the author of these commits to my name?

Solution

This answer uses git-filter-branch, for which the docs now give this warning:

git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave you with little time to investigate such problems since it has such abysmal performance). These safety and performance issues cannot be backward compatibly fixed and as such, its use is not recommended. Please use an alternative history filtering tool such as git filter-repo. If you still need to use git filter-branch, please carefully read SAFETY (and PERFORMANCE) to learn about the land mines of filter-branch, and then vigilantly avoid as many of the hazards listed there as reasonably possible.

Changing the author (or committer) would require re-writing all of the history. If you’re okay with that and think it’s worth it then you should check out git filter-branch. The man page includes several examples to get you started. Also note that you can use environment variables to change the name of the author, committer, dates, etc. — see the "Environment Variables" section of the git man page.

Specifically, you can fix all the wrong author names and emails for all branches and tags with this command (source: GitHub help):

#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Answered By: Anonymous

Related Articles

  • Why do I have to "git push --set-upstream origin "?
  • Why call git branch --unset-upstream to fixup?
  • Checkout another branch when there are uncommitted…
  • Git Using Remote Branch
  • Why does git perform fast-forward merges by default?
  • Difference between git checkout --track…
  • How do I make a Git commit in the past?
  • Git - Pushing code to two remotes
  • How to recover stashed uncommitted changes
  • Why do git fetch origin and git fetch : behave differently?
  • Various ways to remove local Git changes
  • Git workflow and rebase vs merge questions
  • How to remove MySQL completely with config and…
  • Unable to send email using Gmail SMTP server through…
  • What's the difference between HEAD^ and HEAD~ in Git?
  • Git merge with force overwrite
  • Accessing nested JSON with Vue
  • In plain English, what does "git reset" do?
  • What is a tracking branch?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How to create the branch from specific commit in…
  • Multiple elements per v-for loop
  • Examples of GoF Design Patterns in Java's core libraries
  • Why did my Git repo enter a detached HEAD state?
  • Scripting Required for Polymer Submenu/Pages Navigation?
  • Ukkonen's suffix tree algorithm in plain English
  • Why does Git say my master branch is "already up to…
  • Your configuration specifies to merge with the from…
  • How do I delete a Git branch locally and remotely?
  • How to clone ('fork') your own personal GitHub repo…
  • How to pull in changes from skeleton sub-repository…
  • The definitive guide to form-based website authentication
  • Detach (move) subdirectory into separate Git repository
  • Git submodule update
  • Start redis-server with config file
  • How can I reconcile detached HEAD with master/origin?
  • 'block in draw' rails 6 routes
  • What exactly does the "u" do? "git push -u origin…
  • How to cherry pick a range of commits and merge into…
  • Mail not sending with PHPMailer over SSL using SMTP
  • Is it safe to shallow clone with --depth 1, create…
  • Git: Create a branch from unstaged/uncommitted…
  • Switching recipients email address by user…
  • What's the difference between Instant and LocalDateTime?
  • Move the most recent commit(s) to a new branch with Git
  • How do I clone a single branch in Git?
  • What is "git remote add ..." and "git push origin master"?
  • Why does C++ code for testing the Collatz conjecture…
  • Backbone.js: TypeError: Object # has no method 'parse'
  • How to get $HOME directory of different user in bash script?
  • What are the new features in C++17?
  • moving committed (but not pushed) changes to a new…
  • git lfs push to github failure on Ubuntu 18.04
  • Error: Can't set headers after they are sent to the client
  • PHPMailer dont send the pdf attachment
  • How can I send emails through SSL SMTP with the .NET…
  • PHPMailer character encoding issues
  • Retrieve specific commit from a remote Git repository
  • How can I run this simple for loop in parallel bash?
  • Windows git "warning: LF will be replaced by CRLF",…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • How do I revert a Git repository to a previous commit?
  • Php mailer working with utf-8 locally but not on host
  • Change a Git remote HEAD to point to something…
  • How to send 100,000 emails weekly?
  • git pull while not in a git directory
  • Force "git push" to overwrite remote files
  • Git "error: The branch 'x' is not fully merged"
  • How do you stop tracking a remote branch in Git?
  • What are the differences between git remote prune,…
  • Why do I need to do `--set-upstream` all the time?
  • PEAR Mail in php:apache Docker container
  • Why does git say "Pull is not possible because you…
  • How to track untracked content?
  • What's the difference between "git reset" and "git…
  • Send email with PHP from html form on submit with…
  • How do I 'overwrite', rather than 'merge', a branch…
  • git switch branch without discarding local changes
  • Make: "nothing to be done for target" when invoking…
  • Git merge master into feature branch
  • setTimeout function not working : javascript
  • Merge, update, and pull Git branches without using checkouts
  • Logging best practices
  • jmxterm: "Unable to create a system terminal" inside…
  • error: pathspec 'test-branch' did not match any…
  • Getting started with Haskell
  • How to modify existing, unpushed commit messages?
  • Delete all local git branches
  • Failed to authenticate on SMTP server error using gmail
  • What is a NullReferenceException, and how do I fix it?
  • Remove sensitive files and their commits from Git history
  • SMTP connect() failed PHPmailer - PHP
  • Spring Boot: Unable to start…
  • What are the undocumented features and limitations…
  • Why does git status show branch is up-to-date when…
  • What is git tag, How to create tags & How to…
  • Why is processing a sorted array faster than…
  • How to revert multiple git commits?
  • How can I merge two commits into one if I already…
  • How do you get git to always pull from a specific branch?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I center floated elements?

Next Post:

How to Sort Multi-dimensional Array by Value?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error