开发者

Git merge the middle commit in a branch

This is my current repo.

Z(master)---A---B---C---D(branch A)
    开发者_StackOverflow中文版       \
            ---E---F(branch B)

I want to merge commit A to master, can anyone advise how to do that?

(desired)

Z---A(master)---B---C---D(branch A)
     \
      ---E---F(branch B)

EDIT:

The advance of base to branch B from A to B is my typo. Please disregard it. Sorry for the confusing! Even I still learn a trick.


I guess, just like:

git reset master A

BUt only, if the structure is like ths>

<old>---Z<master>A---B---C---D<A>
                      \
                       \
                        \
                         E---F<B>

Afterwards it's like this:

<old>---Z---A<master>B---C---D<A>
                      \
                       \
                        \
                         E---F<B>

Elsewhere, correct your tree please.


If Z is the last commit on master, a simple git merge SHA1(A) will fast-forward master HEAD to A.

However, to advance branchB starting from B (I know, it was a typo in your question), you will need to:

git branch tmp SHA(B)
git checkout branchB
git rebase tmp


You use git merge to merge new changes into a branch. So while you have master checked out

$ git checkout master

you simply merge B.

$ git merge B

For B above, simply use the hash of that commit, or name it with A~3 or similar.

This will fast-forward master to include all commits up to B.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜