简体   繁体   English

在主分支中压缩提交消息

[英]Squash commit message in master branch

In Git after last push to remote repo I worked on master branch. 在Git上次推送到远程仓库后,我在master分支上工作。 I have 6 commits to push now. 我现在有6个提交。 I want to squash these 6 into 1 commit message then do push. 我想将这6个压缩为1个提交消息,然后执行推送。

Any suggestion? 有什么建议吗?

If you are ok with writing a new commit message 如果您可以编写新的提交消息

git reset --soft HEAD~6
git commit

This will the last 6 commits and put them back in the staging area. 这将是最后6次提交并将它们放回暂存区域。 The subsequent commit will then include all the changes. 然后,后续提交将包括所有更改。

If you instead want to preserve the commit messages 如果您想要保留提交消息

git rebase -i HEAD~6

and in the interactive editor, replace 'pick' with 'fixup' for the last 5 commits. 并在交互式编辑器中,将'pick'替换为'fixup',用于最后5次提交。

This will create a unique commit, containing all the 6 commit messages. 这将创建一个唯一的提交,包含所有6个提交消息。

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

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