search

Home  >  Q&A  >  body text

Does git combine rebase --onto and merge --squash operations?

Original:

A---B---C(master)
       /
      D---E---F---G(server)
         /
        H---I(client)

H, I are branched from the server branch, but do not depend on the server. The client has been completed. I want to extract H, I separately and merge it into the master, so I execute git rebase --onto master server client and the result is:

A---B---C(master)---H---I(client)
       /
      D---E---F---G(server)
         /
        H---I

PS: Don’t think the example is strange, it comes from https://git-scm.com/book/en/v2/Git-Branching-Rebasing#More-Interesting-Rebases

The above is the rebase operation, using the merge operation, execute git merge --squash client master; git commit, the result is:

A---B---C(master)---J(D+H+I)
       /
      D---E---F---G(server)
         /
        H---I(client)

Then the question is:
Is there any operation similar to git merge --squash server...client master or git rebase --onto master server client --squash? The effect is as follows:

A---B---C(master)---J(H+I)
       /
      D---E---F---G(server)
         /
        H---I(client)

PS: I know you can rebase --onto to the temp branch first, and then merge --squash to master, but this is too inelegant, isn't it?

巴扎黑巴扎黑2813 days ago724

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-02 09:32:48

    There is an answer already. It is best to use rebase --interactive to mark squash, but I forgot about it:

    git checkout client
    git rebase master -i

    or

    git checkout client
    git reset --soft HEAD~2
    git commit -m 'add client'
    git checkout master
    git cherry-pick client

    Let’s see if you have any other ideas

    reply
    0
  • Cancelreply