Git如何修改历史的Commit信息
2023-07-04 17:51:08
来源:个人图书馆-汉无为
(资料图)
最近由于一行单元测试代码没有写 Assert 断言,导致了项目在 CI 过程中没有通过,于是遭到了某位同事的吐槽,在修改我的代码后写上了一句提交信息。
我想,做为技术人,修改这条 Commit 信息还是不难的,于是我通过本文介绍的技巧完成了修改,效果如下:
其实修改历史提交信息很简单。
对于 git rebase 命令,官方文档 是这样介绍的:允许你在另一个基础分支的头部重新应用提交。
git-rebase - Reapply commits on top of another base tip
使用方法:
我们在执行 git rebase -i
之后,注释里已经给出了所有的用法:
# Rebase 29fc076c..db0768e3 onto 29fc076c (3 commands)## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit# f, fixup = like "squash", but discard this commit"s log message# x, exec = run command (the rest of the line) using shell# b, break = stop here (continue rebase later with "git rebase --continue")# d, drop = remove commit# l, label
归纳一下:
命令 | 缩写 | 含义 |
---|---|---|
pick | p | 保留该commit |
reword | r | 保留该commit,但需要修改该commit的注释 |
edit | e | 保留该commit, 但我要停下来修改该提交(不仅仅修改注释) |
squash | s | 将该commit合并到前一个commit |
fixup | f | 将该commit合并到前一个commit,但不要保留该提交的注释信息 |
exec | x | 执行shell命令 |
drop | d | 丢弃该commit |
标签:
(责任编辑:)