如何修改Github上提交的错误用户地址和姓名

简介: 如何修改Github上提交的错误用户地址和姓名

Changing author info


 https://help.github.com/articles/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 Terminal (for Mac users) or the command prompt (for Windows and Linux users).
  2. Create a fresh, bare clone of your repository:

git clone --bare https://github.com/user/repo.git

cd repo.git


  1. 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


4.Press Enter to run the script.

5.Review the new Git history for errors.

6.Push the corrected history to GitHub:

git push --force --tags origin 'refs/heads/*'


7.Clean up the temporary clone:

cd ..

rm -rf repo.git

目录
相关文章
Github修改仓库的基本信息
我们通常在刚开始了解学习使用github时,一般都是测试的使用,有时我们向里面添加了一些代买,如果想要修改信息并且是删除仓库重新创建提交,可以采用下面方法修改仓库信息,名称、描述等。
277 1
 Github修改仓库的基本信息
|
开发工具 git
关于github默认分支名改为main后可能的处理【git推送到远程不同的分支、github修改默认分支名】
git如何删除本地分支、删除远程分支,由分支的删除可以实现推送到远程不同的分支。 git不允许推送到远程与本地分支名不同的分支上。
810 1
|
JSON 小程序 Java
java oop经典案例开发与源码 -java swing 羊了*羊 简易版本开发 (1) 地图模块编辑器开发(附github源码地址)
java oop经典案例开发与源码 -java swing 羊了*羊 简易版本开发 (1) 地图模块编辑器开发(附github源码地址)
java oop经典案例开发与源码 -java swing 羊了*羊 简易版本开发 (1) 地图模块编辑器开发(附github源码地址)
|
API
gitHub的readme页的卡片和提交活动图的制作方法
gitHub的readme页的卡片和提交活动图的制作方法
291 0
gitHub的readme页的卡片和提交活动图的制作方法
|
Linux 开发工具 git
linux 将本地代码提交至github上(新版图文详解)
linux 将本地代码提交至github上(新版图文详解)
linux 将本地代码提交至github上(新版图文详解)
|
开发工具 git
GitHub/GitLab 为不同的项目修改提交名字 user.name 和邮箱 user.email(附:批量处理脚本)
大疫情的背景下,家里的电脑需要同时支撑自己和公司的项目,根据 GitHub/GitLab 网站的提交记录上看,其是根据邮箱来辨识用户的,所以有必要分别针对不同的项目设置不同的 Git 名字(user.name)和邮箱(user.email)。
467 1
|
测试技术 开发工具 git
git gitee github等系列提交备注规范,提交规范(实用)
git gitee github等系列提交备注规范,提交规范(实用)
542 0
git gitee github等系列提交备注规范,提交规范(实用)
|
IDE Java 开发工具
码云/GitHub Fork代码仓并提交PR代码
背景:在企业开发过程中,都会有自己的代码仓管理,一般会有一个上游代码仓,然后自己fork下该项目,提交到自己下面的项目,并提交PR(或MR)进行合入请求。这里我以码云的代码仓库管理系统为例,演示如何提交代码到上游仓库。 于是有了这一个git代码提交规范,希望能帮助到你。
372 0
码云/GitHub Fork代码仓并提交PR代码
|
开发工具 git
【GitHub】从0开始搭建GitHub环境系列之四——编码并提交GitHub
【GitHub】从0开始搭建GitHub环境系列之四——编码并提交GitHub
108 0
|
开发工具 git
【Git&GitHub - 8】:Git修改文件并提交到本地
【Git&GitHub - 8】:Git修改文件并提交到本地
108 0
【Git&GitHub - 8】:Git修改文件并提交到本地