This repository has been archived on 2025-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
vitepress-theme-blog-charle…/repos/fragments/2022/03/26.修改Git最后一次提交记录的作者和邮箱.md

43 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 修改Git最后一次提交记录的作者和邮箱
author: 查尔斯
date: 2022/03/26 10:30
categories:
- 杂碎逆袭史
tags:
- Git
---
# 修改Git最后一次提交记录的作者和邮箱
## 前言
**C** 今天周末了,抽出了一点时间继续维护下之前提到过的衍生开源项目。修了一个 bug 后,提交了一下。但是突然想起来,今天开发用的是工作本,工作本中的 Git author、email 是配的真实姓名和公司邮箱,提交前忘了修改,现在已经推送到开源平台了,这肯定不行啊。
但是现在即使修改了本地的 Git author、email 配置,历史提交记录也改变不了啊。别着急,看看怎么解决的。
## 问题解决
如果你确定是和笔者一样的情况,即确保是要修改最后一次提交记录,无论有没有推送到远程仓库都没问题。解决方法就两步,是不是很简单?
1. 修改最后一次提交的作者和邮箱信息
```bash
git commit --amend --author="Charles7c <charles7c@126.com>"
```
2. 最后将本地的修改强制推送到远程仓库即可(如果你没推送到远程仓库,这步就不需要执行了)
```bash
git push --force
```
## 后记
**C** 另外说一下,如果你要修改最后一次提交记录的 commit message执行下面的命令就可以了。
```bash
git commit --amend -m "要修改为的提交信息"
```
上方修改作者和邮箱信息的命令,还可以继续加参数 `--date` 来修改提交时间,有需要的话去试试去吧。