简体   繁体   English

git rebase并用一条消息压缩提交

[英]git rebase and squash the commit with a message

Is it possible when we resolve some git conflict via git rebase to squash that rebase via simple message for example "resolve conflicts" . 当我们通过git rebase解决一些git冲突以通过简单的消息(例如"resolve conflicts" git rebase重新压缩数据库时 ,是否可能?
This is my commit history after resolving a specific conflict: 这是解决特定冲突后的提交历史: 在此处输入图片说明

As you see the last 3 commits represent a git rebase then git push -f . 如您所见,最后3次提交代表git rebase然后是git push -f I think it's more logical to set just one commit with a message instead of having 3 (the number of commits on the current branch) commits 我认为只用一条消息设置一个提交而不是3个(当前分支上的提交数量)提交更合乎逻辑

I would recommend doing an interactive rebase, picking the commits you want and the ones you want to squash you prefix with squash instead of pick. 我建议做一个交互式的变基,选择您想要的提交和您想要压榨的提交,并以压榨而不是挑选来作为前缀。

For example in your case it would look something like this (the number is how many commits after HEAD you would like to rebase): 例如,在您的情况下,它看起来像这样(数字是您要重新设置HEAD之后的提交次数):

git rebase -i HEAD~3

You will then get a prompt with the commits and their message which will look something like this: 然后,您将获得有关提交及其消息的提示,如下所示:

pick <HASHID> Initial Commit 
pick <HASHID> Login via mail instead of username
pick <HASHID> Add missing files

Just change the pick to squash (And keep one as the pick commit). 只需将选择权更改为壁球(并保留一个作为选择权提交)。

You will then be able to rewrite that commit message and voila you have 1 commit which you do git push -f if you would like. 然后,您将能够重写该提交消息,瞧,如果您愿意,您可以执行git push -f来执行1次提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM