Git提交作为先前提交的一部分

问题描述

是否可以将更改作为上一次提交的一部分提交?是否喜欢将刚刚更改的内容添加到最新提交中?

解决方法

是的,这叫做修改。

git commit --amend

您甚至可以更改上次提交的提交消息。

git commit --amend --message "my new message"

值得一提的是,即使从人类的角度来看,即使提交是相同的,SHA哈希也会改变,因此,如果出于任何目的通过哈希引用它,该引用将不再起作用。

,

如果要将最后两个修订版本合并为一个修订版本:

git reset --soft HEAD~
git commit --amend --no-edit # use the message from the (originally) 2nd to last revision

或者,您可以设置一条新消息:

git reset --soft HEAD~
git commit --amend -m "new message"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...