Changing author info

To change the name and/or email address recorded in existing commits, you must rewrite the entire history of your Git repository.

Warning: This action is destructive to your repository's history. If you're collaborating on a repository with others, it's considered bad practice to rewrite published history. You should only do this in an emergency.

Changing the Git history of your repository using a script

We've created a script that will change any commits that previously had the old email address in its author or committer fields to use the correct name and email address.

Note: Running this script rewrites history for all repository collaborators. After completing these steps, any person with forks or clones must fetch the rewritten history and rebase any local changes into the rewritten history.

Before running this script, you'll need:

  • The old email address that appears in the author/committer fields that you want to change
  • The correct name and email address that you would like such commits to be attributed to

  1. Open Git Bash.

  2. Create a fresh, bare clone of your repository:

    git clone --bare https://github.com/user/repo.git
    cd repo.git
  3. Copy and paste the script, replacing the following variables based on the information you gathered:

    • OLD_EMAIL
    • CORRECT_NAME
    • CORRECT_EMAIL
#!/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

 
  • Press Enter to run the script.
  • Review the new Git history for errors.
  • Push the corrected history to GitHub:

    git push --force --tags origin 'refs/heads/*'
    
  • Clean up the temporary clone:

    cd ..
    rm -rf repo.git
 

[转] git修改author的更多相关文章

  1. git修改文件名大小写的方法。

    首先,在git命令行里面运行: git config core.ignorecase false 此命令是全局设置,以后在此机子上clone出来的git仓库工程都沿用此设置.当然,以前就已经clone ...

  2. git 修改历史提交信息

    当你不小心,写错了提交的注视/信息,该如何处理呢.理论上,SCM是不应该修改历史的信息的,提交的注释也是.   不过在git中,其commit提供了一个--amend参数,可以修改最后一次提交的信息. ...

  3. git log --author详解,这个是个模糊匹配

    git log --author=authorname --author=<pattern>, commits whose author matches any of the given ...

  4. Git 修改用户名以及提交邮箱

    问题背景: 在已毕业师兄的电脑上提交自己的 Github 代码,(尽管有重新设置了 自己的SSH),但是 Github网站提交结果却显示师兄提交的: 验证当前本地属性: 怎么知道本地有设置?git c ...

  5. git修改用户名以及邮箱

    git 修改当前的project的用户名的命令为:git config user.name 你的目标用户名; git 修改当前的project提交邮箱的命令为:git config user.emai ...

  6. [转]git修改远程仓库地址

    原文链接:http://www.cnblogs.com/lazb/articles/5597878.html 问:Coding远程仓库地址变了,本地git仓库地址如何更新为最新地址 git修改远程仓库 ...

  7. git 修改commit 的注释

    git 修改commit 的注释 一:最新的一次提交 当你不小心,写错了提交的注视/信息,该如何处理呢.理论上,SCM是不应该修改历史的信息的,提交的注释也是.    不过在git中,其commit提 ...

  8. git 修改已提交了的备注信息的方法

    git 修改已提交了的备注信息的方法: 1.当我们已通过 git commit -m '已提交的最新的备注' 命令将代码提交到了缓存区,或者进一步执行了 git push origin master ...

  9. git 修改最后一次提交

    git 修改最后一次提交 有时候我们提交完了才发现漏掉了几个文件没有添加,或者提交信息写错了. 此时,可以运行带有 --amend 选项的提交命令来重新提交:git commit --amend -m ...

随机推荐

  1. 反射 DataTable拓展方法 转实体对象、实体集合、JSON

    Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...

  2. (MVC)验证用户是否登录 登录认证

    验证类 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste ...

  3. IntelIoT技术笔记Maven

    1.Maven project facet配置 错误信息: One or more constraints have not been satisfied.以及Cannot change versio ...

  4. 转:etcd:从应用场景到实现原理的全方位解读

    原文来自于:http://www.infoq.com/cn/articles/etcd-interpretation-application-scenario-implement-principle ...

  5. bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1189  Solved: 734[Submit][ ...

  6. 【技术贴】解决xp下Microsoft.SqlServer.Management.PSProvider.dll

    解决 安装SQLserver2008时有出错信息,提示:Configuration error description: 无法获得 C:\Program Files\Microsoft SQL Ser ...

  7. Servo: The Embeddable Browser Engine

    Embedding, in the context of this article, is the process of hosting a web rendering engine inside a ...

  8. C/C++中的内存对齐 C/C++中的内存对齐

    一.什么是内存对齐.为什么需要内存对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特 定的内存地址 ...

  9. R文件相关(坑)

    大家来找茬...为什么会出现红字,不能正确引用R文件管理的资源呢? 罪魁祸首就是那个import android.R(我根据IDE提示而自作聪明引用的) 删除那行以后,就不会红字了. 刚开始是拷贝了图 ...

  10. Keil C51调试程序时, 对ROM的查看以及RAM 查看或修改

    在Keil 里使用 DeBug 模式时,如要 查看外部 RAM 的数据 或查看 ACC 的内容可以进行以下操作; sysGetTxMode: LCALL Com0185(C:2B95) ,sysGet ...