How to use git merge --squash?

后端 未结 13 1455
夕颜
夕颜 2020-11-22 05:41

I have a remote Git server, here is the scenario which I want to perform:

  • For each bug/feature I create a different Git branch

  • I keep on com

13条回答
  •  误落风尘
    2020-11-22 06:17

    To squash your local branch before pushing it:

    1. checkout the branch in question to work on if it is not already checked out.

    2. Find the sha of the oldest commit you wish to keep.

    3. Create/checkout a new branch (tmp1) from that commit.

      git checkout -b tmp1

    4. Merge the original branch into the new one squashing.

      git merge --squash

    5. Commit the changes which have been created by the merge, with a summary commit message.

      git commit -m

    6. Checkout the original branch you want to squash.

      git checkout

    7. Reset to the original commit sha you wish to keep.

      git reset --soft

    8. Rebase this branch based on the new tmp1 branch.

      git rebase tmp1

    9. That's it - now delete the temporary tmp1 branch once you're sure everything is ok.

提交回复
热议问题