合并(压扁)来自另一个分支的所有更改作为一次提交 [英] Merge (with squash) all changes from another branch as a single commit

查看:60
本文介绍了合并(压扁)来自另一个分支的所有更改作为一次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,是否有一种方法可以将所有更改从一个分支合并到另一个分支,但同时压缩到单个提交?

In Git, is there a way to merge all changes from one branch into another, but squash to a single commit at the same time?

我经常在单独的分支中从事一项新功能,并且会定期提交/推送-主要用于备份或将我正在处理的内容转移到另一台计算机上.通常,那些提交会说功能xxx WIP"或多余的内容.

I often work on a new feature in a separate branch and will regularly commit/push - mainly for backup or to transfer what I'm working on to another machine. Mostly those commits say "Feature xxx WIP" or something redundant.

工作完成后,我想将WIP分支合并回master,我想丢弃所有这些中间提交,而只有一个干净的提交.

Once that work is finished and I want to merge WIP branch back into master, I'd like to discard all those intermediate commits, and just a have a single clean commit.

有没有简单的方法可以做到这一点?

Is there an easy way to do this?

或者,压缩一个分支之后的所有提交的命令又如何呢?

Alternatively, how about a command that squashes all commits on a branch since the point where it was branched?

推荐答案

另一个选项是git merge --squash <feature branch>,然后最后执行git commit.

Another option is git merge --squash <feature branch> then finally do a git commit.

来自 Git合并

--squash

--no-squash

产生工作树和索引状态,就像真正的合并一样 发生了(除了合并 信息),但实际上并没有 提交或移动HEAD,也不记录 $GIT_DIR/MERGE_HEAD导致下一个 git commit命令创建合并 犯罪.这使您可以创建一个 在当前基础上进行单次提交 效果与 合并另一个分支(或更多分支) 章鱼的情况.

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a merge commit. This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

这篇关于合并(压扁)来自另一个分支的所有更改作为一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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