我已经创建了一个测试分支。它有很多微小的提交来构建一个功能。
最后,我想把最后完成的修改,放到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/