惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - Franky
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
量子位
V
Visual Studio Blog
Y
Y Combinator Blog
小众软件
小众软件
N
Netflix TechBlog - Medium
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Change Commit Author Info in Git
2022-08-05 · via jdhao's digital space

This post summarizes how to update author info of Git commits.

For most recent commit#

To change the author info of most recent commit, run

git commit --amend --author="author_name <author_email> --no-edit"

Note that the <> around the email. It is mandatory, otherwise, we see the following weird error:

fatal: No existing author found with ‘xxxx’

If the author has been set in .git/config, we can also simply run:

git commit --amend --reset-author --no-edit

For older commits#

If we want to change the author info for multiple commits, we can use git rebase. For example, suppose we have this commit graph: A->B->C->D->E, we want to change the author of commit B and D. Here is the steps:

  • Run the rebase command, git rebase -i A
  • A vim window opens and you will see a list of commit hash for B, C, D, E, with pick before them.
  • Change pick to edit, before the commit hash for commit B and D.
  • Save and quit vim window :wq
  • Run git commit --amend --author="author_name <author-email>" --no-edit (this is for commit B)
  • Run git rebase --continue to continue the rebase
  • Run git commit --amend --author="author_name <author-email>" --no-edit (this time for commit D)
  • Run git rebase --continue to continue the rebase

The rebase process finishes.

For a range of commits#

If you want to change the author info from an older commit, to the most recent commit, there is a more efficient/faster way than the previous method:

# Note that to also include the root commit, we need to add --root option
git rebase --interactive --exec "git commit --amend --reset-author --no-edit" {commit-ref}

We will a vim window like this:

pick xxx
exec git commit --amend --reset-author --no-edit
pick xxx
exec git commit --amend --reset-author --no-edit
...

Save the quit the window (:wq). The author info for these commits will be changed automatically.

Note that changing the commit author info will change the commit hash for this commit, and also commit hash after that specific commit. So your local commit will diverge with remote if you have pushed those commits to the remote repo.

References#