前言

“嘀嗒嘀嗒”,抬头看向墙上的钟表,此时已是凌晨1点。小明终于把Go语言圣经第二章的笔记写完,保存commit,提交,然后睡觉。

额,等等,不对,小明发现他用的是公司的git账号,git log一看,最新的commit的Author信息里是公司的邮箱地址,尴尬了,难道小明要重新写一遍?“不要啊~”,小明抓狂到。

突然,画面暂停,Git博士从幕后走出,原来是一场电影。Git博士说:“同学们,刚才的案例如果是大家遇到,应该怎样?”,接着说:“不要慌,git rebase帮你解决”

正文

先看一下小明的日志

$git log
commit 34da55544be6ceb1269e24b921275b4a771 (HEAD -> main, origin/main, origin/HEAD)
Author: Company <conpany@company.com>
Date: Mon Jun 8 01:51:52 2021 +0800 commit 3 commit 98f419726756cba7923e3c0062bd1231d25
Author: Ming <ming@ming.com>
Date: Mon Jun 7 20:09:48 2021 +0800 commit 2 commit 15f0d5882db5dedee737a90e3df98bd395
Author: Company <conpany@company.com>
Date: Sat May 15 16:34:06 2021 +0800 commit 1

小明的commit 1commit 3写错了Author信息Company <conpany@company.com>,我们的目标是将这两个commit的作者改成Ming <ming@ming.com> ,让小明早点休息,明天还要去搬砖~

修改上次commit的Author信息

$git commit --commit --author="Ming <ming@ming.com>"

进入一个类似vim编辑器的交互页

commit 3

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author: ming <ming@ming.com>
# Date: Mon Jun 7 22:05:18 2021 +0800
#
# On branch master
#
# On branch main
#
# Changes to be committed:
# new file: ...
#

保存退出即可

修改以前的commit的Author信息

输入下面的命令,-i参数表示交互方式

git rebase -i HEAD~3

进入一个类似vim编辑器的交互页,将要修改的commit 1开头的pick改成edit

edit acdaa07 commit 1
pick 2f30e03 commit 2
pick 34da555 commit 3 # Rebase b94735d..34da555 onto b94735d (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit

然后保存退出,即:wq,输出下面的下面的信息:

You can amend the commit now, with

    git commit --amend 

Once you are satisfied with your changes, run

    git rebase --continue

接着输入下面的命令来修改提交者信息

$git commit --amend --author="Ming <ming@ming.com>"

最后输入保存命令

$git commit --continue
Successfully rebased and updated refs/heads/master.`

我们再来看下小明的日志

$git log
commit 34da55544be6ceb1269e24b921275b4a771 (HEAD -> main, origin/main, origin/HEAD)
Author: Ming <ming@ming.com>
Date: Mon Jun 8 01:51:52 2021 +0800 commit 3 commit 98f419726756cba7923e3c0062bd1231d25
Author: Ming <ming@ming.com>
Date: Mon Jun 7 20:09:48 2021 +0800 commit 2 commit 15f0d5882db5dedee737a90e3df98bd395
Author: Ming <ming@ming.com>
Date: Sat May 15 16:34:06 2021 +0800 commit 1

大功告成,小明终于可以洗洗睡了,明天今天醒来又是美好的一天~

Git修改历史commit的author信息的更多相关文章

  1. Git 修改历史提交信息 commit message

    修改最近一条提交的消息 git commit --amend 进入vim模式 按字母 o 或者 insert键 开始修改内容 按 esc 推出编辑,最常用的是输入":q"直接退出, ...

  2. git 修改历史提交信息

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

  3. 如何修改git commit的author信息

    本地有多个git账号时,容易发生忘记设置项目默认账号,最后以全局账号提交的情况,其实对代码本身并无影响,只是提交记录里显示的是别的名字稍显别扭. 举个例子:  查看提交日志,假设以a(a@email. ...

  4. Git 修改历史 commits 中的用户名和邮箱

    一.作用 修改某个仓库历史 commit 的用户 name 和 email 信息. 将历史提交记录中的指定 name/email 修改为新的 name/email. 二.步骤 确认本地全局邮箱/用户名 ...

  5. Git修改已经提交的用户名信息

    由于工作或者其他原因,有时候我们会修改git的用户名和邮箱账号,没有改过来就提交,就会导致提交人信息不一致的问题.现在记录修正回来的方法 # 第一步,(n)代表提交次数 git rebase -i H ...

  6. git基于历史commit创建分支

    基于以前的commit创建一个分支 步骤: 1.确定需要取出版本的commit值 git log 2.基于该commit创建分支 git branch <branch name> < ...

  7. 批量修改历史commit的用户名user.name邮箱user.email

    配置当前的用户名邮箱可以当前项目配置或者全局配置. 仅当前项目配置: git config user.name 'your-user-name' git config user.email 'your ...

  8. 修改git以往历史中所有commit的name和email

    当换了新的电脑设备或者在 homestead 中使用 git 的时候:如果忘了 git config 设置用户名和邮箱:这样当 git commit 的时候就会使用设备名作为 git 用户名:或者我们 ...

  9. git查看某个文件的修改历史及具体修改内容

    有时候在比对代码时,看到某些改动,但不清楚这个改动的作者和原因,也不知道对应的BUG号,也就是说无从查到这些改动的具体原因了- [注]:某个文件的改动是有限次的,而且每次代码修改的提交都会有commi ...

随机推荐

  1. POJ3048

    素数筛,数据范围不大,直接暴力筛. 坑:有个数据是 1 1,答案是1.差点没把我卡去世. 我的三观哪去了. #include<iostream> #include<cstdio> ...

  2. 【洛谷P1061 Jam的计数法】搜索

    分析 超级暴力,在尾部+1,再判断. AC代码 type arr=array[0..27]of longint; var st:string; a:array[0..27]of longint; s, ...

  3. wait()、notify()、notifyAll()(三)

    有新理解持续更新 轮询 线程本身是操作系统中独立的个体,但是线程与线程之间不是独立的个体,因为它们彼此之间要相互通信和协作. 想像一个场景,A线程做int型变量i的累加操作,B线程等待i到了10000 ...

  4. CSS样式实现表头和列固定

    效果图:第一行和第一列固定       <!DOCTYPE html> <html lang="zh"> <head> <meta cha ...

  5. 解决IDEA右侧maven不显示方法

    解决IDEA右侧maven不显示方法 Ctrl+shift+A --> maven--> add maven projects -->选择对应的pom.xml

  6. 自学linux——16.LAMP项目上线流程

    LAMP项目上线流程 一.编译安装与卸载Nginx(web服务器软件,类似于Apache) 1.安装nginx ①    下载nginx 网页下载https://nginx.org/en/downlo ...

  7. C++ //运算符重载 +号

    1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 //1.成员函数重载 +号 6 cla ...

  8. Http Request Smuggling - Note

    http请求走私漏洞 访问Burp靶场速度感人..都要哭了(如果没有账户的先创建账户) 基础补充 pipeline http1.1有了Pipeline,就不需要等待Server端的响应了.浏览器默认不 ...

  9. 用AutoHotkey做汉字到Unicode字符串的转换

    要把汉字转换为搜的形式,也就是在汉字的Unicode Big Endian编码前面加"&#x",后面加分号.例如""字转换后为"搜" ...

  10. awk-07-IO和printf语句

    IO语句 1.getline 2.getline var 把a文件的行,追加到b文件的结尾 把 a 文件的行替换 b 文件的指定字段 把 a 文件的行替换 b 文件的对应字段 3.command | ...