Git merge testing branch (final commit) to master branch

那年仲夏 提交于 2019-11-29 00:29:54

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.

You are looking for --squash option of 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).

With --no-squash perform the merge and commit the result. This option can be used to override --squash.

So git merge --squash test-branch and commit away.

You may also try git merge --no-commit --no-ff test-branch

git checkout master
git merge --squash testing-branch

That --squash will put your working set in the state as if all the changes on testing-branch got merged in with master, but won't create any commits. You can then do git commit and all the changes will go in in a single commit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!