如何将多个提交合并到另一个分支作为单个压缩提交? [英] How can I merge multiple commits onto another branch as a single squashed commit?

查看:38
本文介绍了如何将多个提交合并到另一个分支作为单个压缩提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程 Git 服务器,这是我想要执行的场景:

I have a remote Git server, here is the scenario which I want to perform:

  • 对于每个错误/功能,我创建一个不同的 Git 分支

  • For each bug/feature I create a different Git branch

我继续使用非官方的 Git 消息在那个 Git 分支中提交我的代码

I keep on committing my code in that Git branch with un-official Git messages

在顶级存储库中,我们必须使用官方 Git 消息对一个错误进行一次提交

In top repository we have to do one commit for one bug with official Git message

那么我怎样才能将我的分支合并到远程分支,以便他们为我的所有签入只获得一次提交(我什至想为此提供提交消息)?

So how can I merge my branch to remote branch so that they get just one commit for all my check-ins (I even want to provide commit message for this)?

推荐答案

假设你的 bug fix 分支叫做 bugfix 并且你想把它合并到 master 中:

Say your bug fix branch is called bugfix and you want to merge it into master:

git checkout master
git merge --squash bugfix
git commit

这将从 bugfix 分支获取所有提交,将它们压缩为 1 个提交,并将其与您的 master 分支合并.

This will take all the commits from the bugfix branch, squash them into 1 commit, and merge it with your master branch.

说明:

git checkout master

切换到您的 master 分支.

git merge --squash bugfix

bugfix 分支获取所有提交,并将其分组为与当前分支的 1 次提交.
(没有出现合并提交;您可以在提交之前手动解决冲突)

Takes all commits from the bugfix branch and groups it for a 1 commit with your current branch.
(no merge commit appears; you could resolve conflicts manually before following commit)

git commit

从合并的更改创建单个提交.

Creates a single commit from the merged changes.

省略 -m 参数可让您在完成提交之前修改包含来自压缩提交的每条消息的草稿提交消息.

Omitting the -m parameter lets you modify a draft commit message containing every message from your squashed commits before finalizing your commit.

这篇关于如何将多个提交合并到另一个分支作为单个压缩提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆