前言

“嘀嗒嘀嗒”,抬头看向墙上的钟表,此时已是凌晨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. if函数+isna函数+vlookup函数实现不同列相同单元格内容排列在同一行

    1,首先学习的网址:https://jingyan.baidu.com/album/22a299b5dd0f959e19376a22.html?picindex=1 2,excel 这也许是史上最好最 ...

  2. SSM框架中mapper层,增删改查,如何实现

    1.批量修改 <!-- 批量修改 MySQL--> <update id="updateBatch" parameterType="java.lang. ...

  3. 浅谈树模型与集成学习-从决策树到GBDT

    引言   神经网络模型,特别是深度神经网络模型,自AlexNet在Imagenet Challenge 2012上的一鸣惊人,无疑是Machine Learning Research上最靓的仔,各种进 ...

  4. Spring Cloud Alibaba基础教程:Sentinel

    随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 是面向分布式服务架构的流量控制组件,主要以流量为切入点,从流量控制.熔断降级.系统自适应保护等多个维度来保障微服务的稳定性. ...

  5. netty系列之:Event、Handler和Pipeline

    目录 简介 ChannelPipeline ChannelHandler ChannelHandlerContext ChannelHandler中的状态变量 异步Handler 总结 简介 上一节我 ...

  6. 痞子衡嵌入式:ARM Cortex-M内核那些事(9.1)- 存储保护(MPU - PMSAv6/7)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是ARM Cortex-M存储保护模块(MPU). <ARM Cortex-M内核MCU开发那些事>的内核篇连载最早是 201 ...

  7. Java基础——逻辑运算符、位运算符

    逻辑运算符.位运算符.三元运算符 逻辑运算符  public class Demon05 {     public static void main(String[] args) {          ...

  8. 串、KMP模式匹配算法

    串是由0个或者多个字符组成的有限序列,又名叫字符串. 串的比较: 串的比较是通过组成串的字符之间的编码来进行的,而字符的编码指的是字符在对应字符集中的序号. 计算机中常用的ASCII编码,由8位二进制 ...

  9. C函数调用(2)

    1 //函数调用 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <math.h> 6 //根据传入 ...

  10. 去除Windows-XP系统下的关机功能

    by han 去除Windows-XP系统下的关机功能 一.去除"开始菜单"中"关机"功能 1.点击左下角"开始",然后"运行&q ...