前言

“嘀嗒嘀嗒”,抬头看向墙上的钟表,此时已是凌晨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. bash shell 遍历一个数组

    var[@]  数组的一个元素 var=("first" "second" "three") for str in ${var[@]}; d ...

  2. MySQL -- 表联结

    创建联结:(使用WHERE联结)SELECTvend_name,prod_name,prod_priceFROMvendors,productsWHEREvendors.vend_id=product ...

  3. 微信小程序云开发-云存储的应用-识别行驶证

    一.准备工作 1.创建云函数identify 2.云函数identify中index.js代码 1 // 云函数入口文件 2 const cloud = require('wx-server-sdk' ...

  4. 第十六篇 -- QListWidget与QToolButton(功能)

    效果图: 添加的部分,就是对几个action绑定了槽函数,完成相应的功能. listWidget操作的都是item,添加一个item,删除一个item,插入一个item等等.那么只需要知道item的几 ...

  5. LeetCode入门指南 之 排序

    912. 排序数组 给你一个整数数组 nums,请你将该数组升序排列. 归并排序 public class Sort { //归并排序 public static int[] MergeSort(in ...

  6. 题解CF757B

    题目 题意:在 \(s\) 数组中找出尽可能多的数使得他们的最大公约数 \(>1\) 既然最大公约数 \(>1\),\(s\) 数组的值域是 \(1 \le s_i \le 10^5\), ...

  7. Cell Reports | 上海瑞金医院糜坚青等揭示组蛋白酰化/乙酰化修饰比率调控BRD4基因组分布

    ​ 景杰生物 | 报道 组蛋白翻译后修饰,被认为构成一类超越基因序列的"组蛋白密码",控制着遗传信息的组织层次及其在染色质层面的解读.组蛋白赖氨酸乙酰化是研究最早的一类组蛋白修饰, ...

  8. Oracle数据泵导入的时候创建索引是否会使用并行?

    一.疑问,Oracle数据泵导入的时候创建索引是否会使用并行? 某客户需要使用数据泵进行迁移,客户咨询导入的时间能不能加快一点. 那么如何加快导入的速度呢? 多加一些并行,那么创建索引内部的索引并行度 ...

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

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

  10. 线程的常用知识(包括 Thread/Executor/Lock-free/阻塞/并发/锁等)

    本次内容列表: 1.使用线程的经验:设置名称.响应中断.使用ThreadLocal 2.Executor:ExecutorService和Future 3.阻塞队列:put和take.offer和po ...