首页 文章

如何在Git中更改多个提交的作者和提交者名称以及电子邮件?

提问于
浏览
2074

我正在学校的计算机上写一个简单的脚本,并将更改提交给Git(在我的pendrive中的repo中,从我家里的计算机克隆) . 经过几次提交,我意识到我是以root用户身份提交的东西 .

有没有办法将这些提交的作者改成我的名字?

30 回答

  • 9

    您可以使用此别名,以便您可以执行以下操作:

    git change-commits GIT_AUTHOR_NAME "old name" "new name"
    

    或者最近10次提交:

    git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com" HEAD~10..HEAD
    

    别名:

    change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" $@; }; f "
    

    资料来源:https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig

    希望它有用 .

  • 5

    我改编了这个solution,通过摄取一个简单的 author-conv-file (格式与git-cvsimport的格式相同) . 它的工作原理是在所有分支中更改 author-conv-file 中定义的所有用户 .

    我们将此与 cvs2git 结合使用,将我们的存储库从cvs迁移到git .

    即样品 author-conv-file

    john=John Doe <john.doe@hotmail.com>
    jill=Jill Doe <jill.doe@hotmail.com>
    

    剧本:

    #!/bin/bash
    
     export $authors_file=author-conv-file
    
     git filter-branch -f --env-filter '
    
     get_name () {
         grep "^$1=" "$authors_file" |
         sed "s/^.*=\(.*\) <.*>$/\1/"
     }
    
     get_email () {
         grep "^$1=" "$authors_file" |
         sed "s/^.*=.* <\(.*\)>$/\1/"
     }
    
     GIT_AUTHOR_NAME=$(get_name $GIT_COMMITTER_NAME) &&
         GIT_AUTHOR_EMAIL=$(get_email $GIT_COMMITTER_NAME) &&
         GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME &&
         GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL &&
         export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
         export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
     ' -- --all
    
  • 2

    请注意,git存储 two 个不同的电子邮件地址,一个用于提交者(提交更改的人),另一个用于作者(编写更改的人) .

    大多数地方都不显示提交者信息,但您可以使用 git log -1 --format=%cn,%ce (或使用 show 而不是 log 来指定特定提交)来查看它 .

    虽然更改上次提交的作者就像 git commit --amend --author "Author Name <email@example.com>" 一样简单,但是没有单行或参数对提交者信息执行相同的操作 .

    解决方案是(暂时或不暂时)更改您的用户信息,然后修改提交,这会将提交者更新为您当前的信息:

    git config user.email my_other_email@example.com 
    git commit --amend
    
  • 159

    最快,最简单的方法是使用git rebase的--exec参数:

    git rebase -i -p --exec 'git commit --amend --reset-author --no-edit'
    

    这将创建一个如下所示的待办事项列表:

    pick ef11092 Blah blah blah
    exec git commit --amend --reset-author --no-edit
    pick 52d6391 Blah bloh bloo
    exec git commit --amend --reset-author --no-edit
    pick 30ebbfe Blah bluh bleh
    exec git commit --amend --reset-author --no-edit
    ...
    

    这将自动完成,当你有数百个提交时,它会工作 .

  • 1453

    正如docgnome所提到的,重写历史是危险的,并将打破其他人的存储库 .

    但是如果你真的想这样做并且你处于bash环境中(在Linux上没有问题,在Windows上,你可以使用git bash,它随git的安装一起提供),请使用git filter-branch

    git filter-branch --env-filter '
      if [ $GIT_AUTHOR_EMAIL = bad@email ];
        then GIT_AUTHOR_EMAIL=correct@email;
      fi;
    export GIT_AUTHOR_EMAIL'
    

    为了加快速度,您可以指定要重写的一系列修订:

    git filter-branch --env-filter '
      if [ $GIT_AUTHOR_EMAIL = bad@email ];
        then GIT_AUTHOR_EMAIL=correct@email;
      fi;
    export GIT_AUTHOR_EMAIL' HEAD~20..HEAD
    
  • 864

    我们今天遇到了一个问题,即作者姓名中的UTF8字符在构建服务器上造成了麻烦,因此我们不得不重写历史记录来纠正这个问题 . 采取的步骤是:

    第1步:根据以下说明,在git中更改所有未来提交的用户名:https://help.github.com/articles/setting-your-username-in-git/

    第2步:运行以下bash脚本:

    #!/bin/sh
    
    REPO_URL=ssh://path/to/your.git
    REPO_DIR=rewrite.tmp
    
    # Clone the repository
    git clone ${REPO_URL} ${REPO_DIR}
    
    # Change to the cloned repository
    cd ${REPO_DIR}
    
    # Checkout all the remote branches as local tracking branches
    git branch --list -r origin/* | cut -c10- | xargs -n1 git checkout
    
    # Rewrite the history, use a system that will preseve the eol (or lack of in commit messages) - preferably Linux not OSX
    git filter-branch --env-filter '
    OLD_EMAIL="me@something.com"
    CORRECT_NAME="New Me"
    
    if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
    then
        export GIT_COMMITTER_NAME="$CORRECT_NAME"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
    then
        export GIT_AUTHOR_NAME="$CORRECT_NAME"
    fi
    ' --tag-name-filter cat -- --branches --tags
    
    # Force push the rewritten branches + tags to the remote
    git push -f
    
    # Remove all knowledge that we did something
    rm -rf ${REPO_DIR}
    
    # Tell your colleagues to `git pull --rebase` on all their local remote tracking branches
    

    快速概述:将存储库签出到临时文件,签出所有远程分支,运行将重写历史记录的脚本,强制推送新状态,并告诉所有同事执行rebase pull以获取更改 .

    我们在OS X上运行它时遇到了麻烦,因为它在某些方面搞砸了提交消息中的行结尾,所以我们不得不在之后的Linux机器上重新运行它 .

  • 1

    我发现所提供的版本是积极的,特别是如果你从其他开发人员提交补丁,这将基本上窃取他们的代码 .

    下面的版本适用于所有分支,并分别更改作者和comitter以防止这种情况 .

    感谢leif81的所有选项 .

    #!/bin/bash
    
    git filter-branch --env-filter '
    if [ "$GIT_AUTHOR_NAME" = "<old author>" ];
    then
        GIT_AUTHOR_NAME="<new author>";
        GIT_AUTHOR_EMAIL="<youmail@somehost.ext>";
    fi
    if [ "$GIT_COMMITTER_NAME" = "<old committer>" ];
    then
        GIT_COMMITTER_NAME="<new commiter>";
        GIT_COMMITTER_EMAIL="<youmail@somehost.ext>";
    fi
    ' -- --all
    
  • 5

    我使用以下内容为整个存储库重写作者,包括标记和所有分支:

    git filter-branch --tag-name-filter cat --env-filter "
      export GIT_AUTHOR_NAME='New name';
      export GIT_AUTHOR_EMAIL='New email'
    " -- --all
    

    然后,如MAN page of filter-branch中所述,删除由 filter-branch 备份的所有原始引用(这是破坏性的,先备份):

    git for-each-ref --format="%(refname)" refs/original/ | \
    xargs -n 1 git update-ref -d
    
  • 108
    git rebase -i YOUR_FIRTS_COMMIT_SHA^
    
    while true; do git commit --amend --author="Name Surname <email@example.com>" --no-edit && git rebase --continue; done
    

    在rebase完成后按^ C#(循环将继续更新上次提交)

  • 6

    Github有一个nice solution,它是以下shell脚本:

    #!/bin/sh
    
    git filter-branch --env-filter '
    
    an="$GIT_AUTHOR_NAME"
    am="$GIT_AUTHOR_EMAIL"
    cn="$GIT_COMMITTER_NAME"
    cm="$GIT_COMMITTER_EMAIL"
    
    if [ "$GIT_COMMITTER_EMAIL" = "your@email.to.match" ]
    then
        cn="Your New Committer Name"
        cm="Your New Committer Email"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "your@email.to.match" ]
    then
        an="Your New Author Name"
        am="Your New Author Email"
    fi
    
    export GIT_AUTHOR_NAME="$an"
    export GIT_AUTHOR_EMAIL="$am"
    export GIT_COMMITTER_NAME="$cn"
    export GIT_COMMITTER_EMAIL="$cm"
    '
    
  • 180

    如果您是此存储库的唯一用户,则可以 rewrite history 使用git filter-branch(作为svick wrote)或git fast-export / git fast-import加过滤器脚本(如docgnome answer中引用的文章中所述)或交互式rebase . 但是其中任何一个都会改变第一次更改提交的修订;这对于任何基于他/她的分支预先重写的更改的人来说意味着麻烦 .

    RECOVERY

    如果其他开发人员没有将他们的工作基于预重写版本,那么最简单的解决方案就是重新克隆(再次克隆) .

    或者他们可以尝试 git rebase --pull ,如果他们的存储库没有任何更改,它会快进,或者在重写提交之后重新绑定他们的分支(我们希望避免合并,因为它将永远保留预重写命令) . 所有这一切都假设他们没有做过工作;使用 git stash 来隐藏更改 .

    如果其他开发人员使用功能分支,和/或 git pull --rebase 不起作用,例如因为没有设置上游,所以他们必须在重写后提交的基础上进行工作 . 例如,在获取新更改( git fetch )之后,对于 master 分支,基于/分叉自 origin/master ,需要运行

    $ git rebase --onto origin/master origin/master@{1} master
    

    这里 origin/master@{1} 是预重写状态(在获取之前),请参阅gitrevisions .


    替代解决方案是使用 refs/replace/ 机制,自1.6.5版以来在Git中可用 . 在此解决方案中,您为具有错误电子邮件的提交提供替换;那么任何拿出'replace' refs( fetch = +refs/replace/*:refs/replace/* refspec在 .git/config 中的适当位置)的人都会透明地获得替换,而那些不获取这些refs的人会看到旧的提交 .

    程序如下:

    • 查找所有提交错误电子邮件的提交,例如使用
    $ git log --author=user@wrong.email --all
    
    • 对于每个错误的提交,创建替换提交,并将其添加到对象数据库
    $ git cat-file -p <ID of wrong commit> | 
      sed -e 's/user@wrong\.email/user@example.com/g' > tmp.txt
    $ git hash-object -t commit -w tmp.txt
    <ID of corrected commit>
    
    • 现在您已经更正了对象数据库中的提交,您必须告诉git使用git replace命令自动并透明地替换错误的提交:
    $ git replace <ID of wrong commit> <ID of corrected commit>
    
    • 最后,列出所有替换以检查此过程是否成功
    $ git replace -l
    

    并检查是否有替换

    $ git log --author=user@wrong.email --all
    

    你当然可以自动执行这个程序......好吧,除了使用 git replace 之外没有(还有)批处理模式,所以你必须使用shell循环,或者替换"by hand" .

    NOT TESTED! YMMV .

    请注意,使用refs / replace / mechanism时可能会遇到一些粗糙的问题:它是新的,还没有经过很好的测试 .

  • 15

    如果您使用Eclipse与EGit,那么有一个非常简单的解决方案 .
    假设:您在本地分支'local_master_user_x'中提交,由于用户无效,无法将其推送到远程分支'master' .

    • 结帐远程分支'master'

    • 选择'local_master_user_x'包含更改的项目/文件夹/文件

    • 右键单击 - 替换为 - 分支 - 'local_master_user_x'

    • 再次提交这些更改,这次是正确的用户并进入本地分支'master'

    • 推送到远程'master'

  • 23

    如果您要修复的提交是最新的,只有其中几个,您可以使用 git resetgit stash 的组合在配置正确的名称和电子邮件后再次提交它们 .

    序列将是这样的(对于2个错误的提交,没有挂起的更改):

    git config user.name <good name>
    git config user.email <good email>
    git reset HEAD^
    git stash
    git reset HEAD^
    git commit -a
    git stash pop
    git commit -a
    
  • 18

    如果您是此回购的唯一用户,或者您不关心可能为其他用户破坏回购,那么是 . 如果你已经推送了这些提交并且它们存在于其他地方可以访问它们的地方,那么不,除非你不关心打破其他人的回购 . 问题是通过更改这些提交,您将生成新的SHA,这将导致它们被视为不同的提交 . 当其他人试图引入这些已更改的提交时,历史记录会有所不同而且kaboom .

    这个页面http://inputvalidation.blogspot.com/2008/08/how-to-change-git-commit-author.html描述了如何做到这一点 . (我没试过这么YMMV)

  • 5

    我应该指出,如果唯一的问题是作者/电子邮件与平常不同,这不是问题 . 正确的解决方法是在目录的底部创建一个名为 .mailmap 的文件,其中包含类似的行

    Name you want <email you want> Name you don't want <email you don't want>
    

    从那时起,像 git shortlog 这样的命令会认为这两个名字是相同的(除非你明确告诉他们不要) . 有关更多信息,请参见http://schacon.github.com/git/git-shortlog.html .

    这具有所有其他解决方案的优点,因为您不必重写历史记录,如果您有上游,这可能会导致问题,并且始终是意外丢失数据的好方法 .

    当然,如果你做了自己的事情并且应该真的是其他人,并且你不介意重写历史记录,那么更改提交作者可能是一个好主意用于归因目的(在这种情况下我指导你到我的这里的其他答案) .

  • 38

    如果只有前几个提交有不好的作者,你可以使用 exec 命令和 --amend 提交在 git rebase -i 内完成所有这些操作,如下所示:

    git rebase -i HEAD~6 # as required
    

    它为您提供了可编辑的提交列表:

    pick abcd Someone else's commit
    pick defg my bad commit 1
    pick 1234 my bad commit 2
    

    然后在所有具有错误作者的行之后添加 exec ... --author="..." 行:

    pick abcd Someone else's commit
    pick defg my bad commit 1
    exec git commit --amend --author="New Author Name <email@address.com>" -C HEAD
    pick 1234 my bad commit 2
    exec git commit --amend --author="New Author Name <email@address.com>" -C HEAD
    

    保存并退出编辑器(运行) .

    这个解决方案可能比其他解决方案更长,但它是高度可控的 - 我确切地知道它所提交的提交内容 .

    感谢@asmeurer的灵感 .

  • 3

    一个班轮,但如果你有一个多用户存储库,要小心 - 这将改变所有提交以拥有相同(新)作者和提交者 .

    git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='new@email'; GIT_COMMITTER_NAME='Newname'; GIT_COMMITTER_EMAIL='new@email';" HEAD
    

    使用字符串中的换行符(可以在bash中使用):

    git filter-branch -f --env-filter "
        GIT_AUTHOR_NAME='Newname'
        GIT_AUTHOR_EMAIL='new@email'
        GIT_COMMITTER_NAME='Newname'
        GIT_COMMITTER_EMAIL='new@email'
      " HEAD
    
  • 0

    你也可以这样做:

    git filter-branch --commit-filter '
            if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
            then
                    GIT_COMMITTER_NAME="<New Name>";
                    GIT_AUTHOR_NAME="<New Name>";
                    GIT_COMMITTER_EMAIL="<New Email>";
                    GIT_AUTHOR_EMAIL="<New Email>";
                    git commit-tree "$@";
            else
                    git commit-tree "$@";
            fi' HEAD
    

    注意,如果在Windows命令提示符下使用此命令,则需要使用 " 而不是 '

    git filter-branch --commit-filter "
            if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
            then
                    GIT_COMMITTER_NAME="<New Name>";
                    GIT_AUTHOR_NAME="<New Name>";
                    GIT_COMMITTER_EMAIL="<New Email>";
                    GIT_AUTHOR_EMAIL="<New Email>";
                    git commit-tree "$@";
            else
                    git commit-tree "$@";
            fi" HEAD
    
  • 79

    This is a more elaborated version of @Brian's version:

    要更改作者和提交者,您可以执行此操作(在bash中可以使用字符串中的换行符):

    git filter-branch --env-filter '
        if [ "$GIT_COMMITTER_NAME" = "<Old name>" ];
        then
            GIT_COMMITTER_NAME="<New name>";
            GIT_COMMITTER_EMAIL="<New email>";
            GIT_AUTHOR_NAME="<New name>";
            GIT_AUTHOR_EMAIL="<New email>";
        fi' -- --all
    

    您可能会收到以下错误之一:

    • 临时目录已存在

    • 以refs / original开头的Refs已经存在
      (这意味着先前已在存储库上运行了另一个filter-branch,然后在refs / original处备份了原始分支引用)

    如果你想强迫尽管存在这些错误,但添加 --force 标志:

    git filter-branch --force --env-filter '
        if [ "$GIT_COMMITTER_NAME" = "<Old name>" ];
        then
            GIT_COMMITTER_NAME="<New name>";
            GIT_COMMITTER_EMAIL="<New email>";
            GIT_AUTHOR_NAME="<New name>";
            GIT_AUTHOR_EMAIL="<New email>";
        fi' -- --all
    

    可能需要对 -- --all 选项进行一些解释:它使filter-branch适用于所有refs(包括所有分支)的所有修订 . 这意味着,例如,标签也被重写并在重写的分支上可见 .

    常见的"mistake"是使用 HEAD 代替,这意味着只过滤当前分支上的所有修订 . 然后在重写的分支中不存在标签(或其他引用) .

  • 17

    当接管来自另一位作者的未合并提交时,有一种简单的方法可以解决这个问题 .

    git commit --amend --reset-author

  • 5

    我也想添加我的例子 . 我想创建一个 bash_function with given parameter.

    这适用于mint-linux-17.3

    # $1 => email to change, $2 => new_name, $3 => new E-Mail
    
    function git_change_user_config_for_commit {
    
     # defaults
     WRONG_EMAIL=${1:-"you_wrong_mail@hello.world"}
     NEW_NAME=${2:-"your name"}
     NEW_EMAIL=${3:-"new_mail@hello.world"}
    
     git filter-branch -f --env-filter "
      if [ \$GIT_COMMITTER_EMAIL = '$WRONG_EMAIL' ]; then
        export GIT_COMMITTER_NAME='$NEW_NAME'
        export GIT_COMMITTER_EMAIL='$NEW_EMAIL'
      fi
      if [ \$GIT_AUTHOR_EMAIL = '$WRONG_EMAIL' ]; then
        export GIT_AUTHOR_NAME='$NEW_NAME'
        export GIT_AUTHOR_EMAIL='$NEW_EMAIL'
      fi
     " --tag-name-filter cat -- --branches --tags;
    }
    
  • 0

    使用Interactive Rebase

    你可以做到

    git rebase -i -p <some HEAD before all of your bad commits>
    

    然后将所有错误提交标记为rebase文件中的“edit” . 如果您还想更改第一次提交,则必须手动将其添加为rebase文件中的第一行(遵循其他行的格式) . 然后,当git要求你修改每个提交时,做

    git commit --amend --author "New Author Name <email@address.com>"
    

    编辑或只关闭打开的编辑器,然后执行

    git rebase --continue
    

    继续坚持 .

    您可以通过附加 --no-edit 来完全打开编辑器,这样命令将是:

    git commit --amend --author "New Author Name <email@address.com>" --no-edit && \
    git rebase --continue
    

    单一提交

    正如一些评论者所指出的,如果您只想更改最近的提交,则不需要rebase命令 . 做就是了

    git commit --amend --author "New Author Name <email@address.com>"
    

    这会将作者更改为指定的名称,但提交者将在 git config user.namegit config user.email 中设置为已配置的用户 . 如果要将提交者设置为您指定的内容,则会设置作者和提交者:

    git -c user.name="New Author Name" -c user.email=email@address.com commit --amend --reset-author
    

    关于合并提交的注意事项

    我最初的反应存在轻微缺陷 . 如果当前 HEAD 和你的 <some HEAD before all your bad commits> 之间有任何合并提交,那么 git rebase 将展平它们(顺便说一句,如果你使用GitHub拉取请求,你的历史记录中将会有大量的合并提交) . 这通常会导致非常不同的历史记录(因为重复更改可能是"rebased out"),并且在最坏的情况下,它可能导致 git rebase 要求您解决困难的合并冲突(可能已在合并提交中解决) . 解决方案是使用 -p 标志 git rebase ,这将保留历史记录的合并结构 . git rebase 的联机帮助页警告说使用 -p-i 会导致问题,但在 BUGS 部分中它说"Editing commits and rewording their commit messages should work fine."

    我在上面的命令中添加了 -p . 对于刚刚更改最新提交的情况,这不是问题 .

  • 20

    当您没有初始化$ HOME / .gitconfig时会发生这种情况 . 你可以解决这个问题:

    git config --global user.name "you name"
    git config --global user.email you@domain.com
    git commit --amend --reset-author
    

    用git版本1.7.5.4测试

  • 571

    试试吧 . 它将与上面提到的相同,但是交互式 .

    bash <(curl -s  https://raw.githubusercontent.com/majdarbash/git-author-change-script/master/run.sh)
    

    参考:https://github.com/majdarbash/git-author-change-script

  • 497
    • Amend 更改提交 author name & email ,然后替换 old-commit with new-one
    $ git checkout <commit-hash>                            # checkout to the commit need to modify  
    $ git commit --amend --author "name <author@email.com>" # change the author name and email
    
    $ git replace <old-commit-hash> <new-commit-hash>      # replace the old commit by new one
    $ git filter-branch -- --all                           # rewrite all futures commits based on the replacement                   
    
    $ git replace -d <old-commit-hash>     # remove the replacement for cleanliness 
    $ git push -f origin HEAD              # force push
    
    • 另一种方式 Rebasing
    $ git rebase -i <good-commit-hash>      # back to last good commit
    
    # Editor would open, replace 'pick' with 'edit' before the commit want to change author
    
    $ git commit --amend --author="author name <author@email.com>"  # change the author name & email
    
    # Save changes and exit the editor
    
    $ git rebase --continue                # finish the rebase
    
  • 206
    • 运行 git rebase -i <sha1 or ref of starting point>

    • 使用 edit (或 e )标记要更改的所有提交

    • 循环以下两个命令,直到您处理完所有提交:

    git commit --amend --reuse-message=HEAD --author="New Author <new@author.email>" ; git rebase --continue

    这将保留所有其他提交信息(包括日期) . --reuse-message=HEAD 选项阻止消息编辑器启动 .

  • 46

    对于单个提交:

    git commit --amend --author="Author Name <email@address.com>"
    

    (从asmeurer的答案中提取)

  • 37

    使用交互式rebase,您可以在每次要更改的提交后放置修改命令 . 例如:

    pick a07cb86 Project tile template with full details and styling
    x git commit --amend --reset-author -Chead
    
  • 5

    更改作者(或提交者)将需要重写所有历史记录 . 如果你're okay with that and think it'值得,那么你应该看看git filter-branch . 手册页包含几个示例以帮助您入门 . 另请注意,您可以使用环境变量来更改作者,提交者,日期等的名称 - 请参阅git man page的"Environment Variables"部分 .

    具体来说,您可以使用此命令修复所有错误的作者姓名和电子邮件 for all branches and tags (来源:GitHub help):

    #!/bin/sh
    
    git filter-branch --env-filter '
    OLD_EMAIL="your-old-email@example.com"
    CORRECT_NAME="Your Correct Name"
    CORRECT_EMAIL="your-correct-email@example.com"
    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
    
  • 21

    你的问题很常见 . 见“Using Mailmap to Fix Authors List in Git

    为简单起见,我创建了一个脚本来简化流程:git-changemail

    将该脚本放在路径上后,您可以发出如下命令:

    • 更改当前分支上的作者匹配
    $ git changemail -a old@email.com -n newname -m new@email.com
    
    • 在<branch>和<branch2>上更改作者和提交者匹配 . 将 -f 传递给filter-branch以允许重写备份
    $ git changemail -b old@email.com -n newname -m new@email.com -- -f &lt;branch> &lt;branch2>
    
    • 在repo上显示现有用户
    $ git changemail --show-both
    

    顺便说一句,在进行更改后,使用以下命令清除filter-branch中的备份:git-backup-clean

相关问题