前言

“嘀嗒嘀嗒”,抬头看向墙上的钟表,此时已是凌晨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. 【模拟】报名签到 luogu-4445

    AC代码 #include <bits/stdc++.h> using namespace std; #define ms(a,b) memset(a,b,sizeof(a)) typed ...

  2. PGSQL数据库里物化视图【materialized view】

    1.普通视图 数据库中的视图(view)是从一张或多张数据库表查询导出的虚拟表,反映基础表中数据的变化,且本身不存储数据. 2.物化视图[materialized view]     2.1.概念:  ...

  3. Python - 基础数据类型 set 集合

    集合的简介 集合是一个无序.不重复的序列 它的基本用法包括成员检测和消除重复元素 集合对象也支持像 联合,交集,差集,对称差分等数学运算 集合中所有的元素放在 {} 中间,并用逗号分开 集合的栗子 这 ...

  4. Spring WebFlux 基础教程:参数校验

    请求参数校验,在实际的应用中很常见,网上的文章大部分提供的使用注解的方式做参数校验.本文主要介绍 Spring Webflux Function Endpoint 使用 Spring Validati ...

  5. netty系列之:中国加油

    目录 简介 场景规划 启动Server 启动客户端 消息处理 消息处理中的陷阱 总结 简介 之前的系列文章中我们学到了netty的基本结构和工作原理,各位小伙伴一定按捺不住心中的喜悦,想要开始手写代码 ...

  6. 原生ajax练习-post&xml

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 有赞Android实习五面都挂了,复习半月再战,转拿腾讯offer!

    缘起 为了有赞的面试准备了半个月的样子,当时还投了美团.字节.滴滴.京东,目的只有一个,就是要进大厂,但是只有有赞扛过了一面,其他都是一面就挂了. 前三面都自我感觉良好,以为能稳拿offer的,没想到 ...

  8. OpenStack中VNC协议实现多屏共享(多屏不踢访问)

    OpenStack中VNC协议实现多屏共享 by 无若   libvirt设置基本说明:   <devices> <graphics type='sdl' display=':0.0 ...

  9. Python -类型提示 Type Hints

    为什么会有类型提示 Python是一种动态类型语言,这意味着我们在编写代码的时候更为自由,运行时不需要指定变量类型 但是与此同时 IDE 无法像静态类型语言那样分析代码,及时给我们相应的提示,比如字符 ...

  10. Create Shortcut to Get Jar File Meta Information

    You have to get meta information of cobertura.jar with command "unzip -q -c cobertura.jar META- ...