Git merge 测试分支(最终提交)到 master 分支

标签 git merge branch final

我已经创建了一个测试分支。它有很多微小的提交来构建一个功能。 最后,我想把最后完成的修改,放到master分支。
主分支,不应该包含测试分支的历史。
最终将删除测试分支。

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

最佳答案

Understanding the Git Workflow”中描述了各种方法:

短暂的工作

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

更大的工作

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

(正如您在问题中提到的那样,您的情况不是一个选项)

宣布分行破产

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 merge 测试分支(最终提交)到 master 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9107861/

相关文章:

Git 存储库未导出 : fatal: The remote end hung up unexpectedly

git - 链接到 GitHub 上的特定(当前)修订版

git - GIT中的 'Commit ID'和 'SHA1 Hash'有什么区别?

javascript - 在 three.js 中合并几何

git - 无法检索 git 提交

git - 为什么 git 不知道我 merge 了?有没有办法告诉它?

oracle - 访问合并语句中的值

check out 其他分支时的 Git fetch/rebase master 分支

git - 当我还没有准备好提交时,如何在 git 分支中隔离我的更改?

git - 检查 git 分支是否在 azure devops 上使用 api 被锁定