首页 > 解决方案 > Squash 2 commits into 1

问题描述

I have two commits locally:

commit adae40c5e2b69a41447b08cc3dcb77003611fbbe
Author: Me
Date:   Thu Mar 21 14:17:35 2019 +0000

    1.0.0

commit ceaa65ea06f48dc24554a6f798aae2d668f3a43d
Author: Me
Date:   Fri Feb 1 10:04:36 2019 +0000

    first commit

How do I squash these so there is only one commit with the message 1.0.0?

I tried the following but neither has worked for me:

git rebase -i HEAD~2
git rebase -i master

标签: gitgit-rebasegit-squash

解决方案


For those not fond of interactive rebasing, in a situation like this it's also quite easy to just rewind and recommit :

git reset --soft HEAD~2
git commit -m "1.0.0"

推荐阅读