将一些最近的git commit变成一次commit

时间:2019-07-05 17:47:49

标签: git github gitlab

例如,我当前分支中有10个提交,现在我想将最后4个提交变成一个提交...我已将所有提交推送到我的远程分支..现在我可以使我的最后4个提交消息进入新的提交消息?

我想这样做,因为,我的最后4条提交消息毫无意义...

我尝试过这样:

git rebase -i HEAD~2

它会向我发送消息,例如,我已经成功重新设置了基准,但是稍后,我尝试推送此消息,它说,没什么可提交的。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:4)

如果您的分支可以在远程上重写,则可以这样做:

git checkout my-branch
git reset --soft my-branch~4 # set branch pointer 4 revisions behind... put all differences between the 4 revisions on index
git commit -m "The messsage I want"
# if you like the result
git push the-remote my-branch

就应该这样。

答案 1 :(得分:2)

您可以使用--soft标志还原最近的四次提交,然后进行新的提交。看看这个question