Git 将测试分支(最终提交)合并到主分支 [英] Git merge testing branch (final commit) to master branch

查看:77
本文介绍了Git 将测试分支(最终提交)合并到主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个测试分支.它有很多微小的提交来构建一个功能.最后,我想把最后完成的更改,放到 master 分支.
主分支,不应包含测试分支的历史记录.
测试分支最终会被移除.

实现这一目标的最佳方法是什么?
生成补丁并将其应用到 master 上是最好的方法吗?
如果是这样,我如何生成/应用补丁?

解决方案

中描述了各种方法理解 Git 工作流程":

短期工作

<块引用>

在绝大多数情况下,我的清理只是一个壁球合并.

git checkout mastergit merge --squash private_feature_branchgit commit -v

更大的工作

<块引用>

我决定我的变化应该分解成更小的变化,所以壁球是一种过于生硬的乐器.(根据经验,我会问:这是否容易进行代码审查?")

git rebase --interactive master

(正如您在问题中提到的那样,这不是您的选择)

宣布分行破产

<块引用>

也许我的功能分支存在很长时间了,我不得不将几个分支合并到我的功能分支中以在我工作时保持它的最新状态.历史是错综复杂的.
获取原始差异创建一个干净的分支是最简单的.

git checkout mastergit checkout -bclean_up_branchgit merge --squash private_feature_branch重置

<块引用>

我现在有一个工作目录,里面装满了我的更改,没有前一个分支的包袱.现在我手动添加并提交更改.

I have created a testing branch. It has a lot of tiny commits to build one feature. At the end of it, I want to take the final completed changes, and put them into the master branch.
The master branch, shouldn't contain the history of the testing branch.
Testing branch will be removed eventually.

What is the best way to achieve this?
Would generating a patch and applying it on master be the best way?
If so, how do I generate/apply the patch?

解决方案

Various approaches are described in "Understanding the Git Workflow":

Short lived work

The vast majority of the time, my cleanup is just a squash merge.

git checkout master
git merge --squash private_feature_branch
git commit -v

Larger work

I decide my change should be broken into smaller changes, so squash is too blunt an instrument. (As a rule of thumb I ask, "Would this be easy to code review?")

git rebase --interactive master

(not an option in your case, as you mention in your question)

Declaring Branch Bankruptcy

Maybe my feature branch existed for a very long time, and I had to merge several branches into my feature branch to keep it up to date while I work. History is convoluted.
It’s easiest to grab the raw diff create a clean branch.

git checkout master
git checkout -b cleaned_up_branch
git merge --squash private_feature_branch
git reset

I now have a working directory full of my changes and none of the baggage from the previous branch. Now I manually add and commit my changes.

这篇关于Git 将测试分支(最终提交)合并到主分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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