当前位置: 首页 > 资讯 > >正文

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

归纳一下:

命令缩写含义
pickp保留该commit
rewordr保留该commit,但需要修改该commit的注释
edite保留该commit, 但我要停下来修改该提交(不仅仅修改注释)
squashs将该commit合并到前一个commit
fixupf将该commit合并到前一个commit,但不要保留该提交的注释信息
execx执行shell命令
dropd丢弃该commit

X 关闭

推荐内容

最近更新

Copyright ©  2015-2022 西方珠宝网版权所有  备案号:沪ICP备2020036824号-7   联系邮箱:5 626 629 @qq.com