-2

In git, I would like to amend my name and email address for the entire history of a repository.

Is there a command to do this and if there is, are there any risks associated with doing this?

Marty Wallace
  • 34,046
  • 53
  • 137
  • 200
  • 1
    Stack Overflow shouldn't replace some basic research you do on your own. When I Google `Git: Change name and email across entire repository history` I seem to get a lot of useful results? – Pekka Apr 25 '16 at 09:41
  • It's called `filter-branch` and it will recreate every commit involved and any commit that (indirectly) depends on them. That will change the hash of every commit and if somebody else has the repo checked out they will hate you for doing it. In general it's better to leave old commits be since I don't think your name/email can change retroactively, and use the new name and email for new commits. – Matti Virkkunen Apr 25 '16 at 09:42
  • To reiterate I'd reserve `filter-branch` for extreme cases, e.g. when you need to, say, delete illegal material that somehow ended up in a repo. Not because somebody's name changed. – Matti Virkkunen Apr 25 '16 at 09:45
  • @MattiVirkkunen That's useful advice for bigger projects, but there can be other legitimate reasons for doing something like this e.g. a one person project, where you made a typo, or want to change the name or email address prior to making your repo public. – JBentley Apr 25 '16 at 10:11
  • @JBentley: Just making it sound like a big deal because unless it's a personal project it is. I did mention that people would only hate you if they have your code checked out or something, and if nobody else has access to the repo (or only a few people you know), then you can coordinate with them to make the change without breaking everything. – Matti Virkkunen Apr 25 '16 at 10:15

1 Answers1

0

Here is a snippet code for you to use. (should be single line, breaked for formatting)

You can change any value - name/email etc.

git filter-branch --commit-filter 
    'if [ "$GIT_AUTHOR_NAME" = "old_name" ];
        then 
            export GIT_AUTHOR_NAME="new_name"; 
            export GIT_AUTHOR_EMAIL="new_email";
     fi; 
     git commit-tree "$@"
'

There are more options if you want to use them but this is.

Read the full documentation here and in particular about git filter-branch as well.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167