Git重写上一次commit信息

我们有时commit后才突然发现刚才的信息没有写好,想重新写怎么办?

这时候可以用以下这条简单的命令实现上一条commit信息改写

【国内直连ChatGPT 29元起】
国内直连ChatGPT,Plus会员每月29元起,支持最新o1模型探索更多领域,无需注册OpenAI账号。

git commit --amend

看看这条命令的解释

--amend
        Replace the tip of the current branch by creating a new commit. The
        recorded tree is prepared as usual (including the effect of the -i
        and -o options and explicit pathspec), and the message from the
        original commit is used as the starting point, instead of an empty
        message, when no other message is specified from the command line
        via options such as -m, -F, -c, etc. The new commit has the same
        parents and author as the current one

执行git commit --amend后会自动进入上一次提交信息的编辑状态,改完后保存退出就好

分享

TITLE: Git重写上一次commit信息

LINK: https://www.qttc.net/196-git-amend-last-commit.html

NOTE: 原创内容,转载请注明出自琼台博客