将来自另一个分支的所有更改合并为一次提交 [英] Merge all changes from another branch as a single commit

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

问题描述

在Git中,有没有办法将所有的更改从一个分支合并到另一个分支,但同时压缩到单个提交?

我经常在一个单独的分支中开发新功能,并定期提交/推送 - 主要用于备份或将正在处理的内容传输到另一台计算机。大多数情况下,这些提交表示Feature xxx WIP或其他冗余。



一旦这项工作完成并且我想将WIP分支合并回主设备,我想放弃所有这些中间提交,只是一个简单的提交。



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

另外,如果一个命令将分支上的所有提交合并为一个命令,那么它如何分支?

解决方案

另一个选项是 git merge --squash< feature branch> 然后最后做一个 git commit



From Git merge


- squash $ b $ p code - no-squash



产生工作树和索引状态,就好像真正的合并
发生了(合并
信息除外),但实际上并没有使
a提交或移动 HEAD ,也不记录
$ GIT_DIR / MERGE_HEAD ,导致下一个
git commit 命令创建合并
提交。这允许你在当前的
分支之上创建一个
的单个提交,其效果与合并另一个分支的
相同(或者更多的是
的章鱼)。



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?

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.

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?

解决方案

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

From Git merge

--squash

--no-squash

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天全站免登陆