Hot For Coding
Git重写上一次commit信息

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

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

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: 转载本站文章请注明作者和出处