Squash my last X commits together using Git

前端 未结 30 3380
醉酒成梦
醉酒成梦 2020-11-21 05:17

How can I squash my last X commits together into one commit using Git?

30条回答
  •  温柔的废话
    2020-11-21 05:31

    What about an answer for the question related to a workflow like this?

    1. many local commits, mixed with multiple merges FROM master,
    2. finally a push to remote,
    3. PR and merge TO master by reviewer. (Yes, it would be easier for the developer to merge --squash after the PR, but the team thought that would slow down the process.)

    I haven't seen a workflow like that on this page. (That may be my eyes.) If I understand rebase correctly, multiple merges would require multiple conflict resolutions. I do NOT want even to think about that!

    So, this seems to work for us.

    1. git pull master
    2. git checkout -b new-branch
    3. git checkout -b new-branch-temp
    4. edit and commit a lot locally, merge master regularly
    5. git checkout new-branch
    6. git merge --squash new-branch-temp // puts all changes in stage
    7. git commit 'one message to rule them all'
    8. git push
    9. Reviewer does PR and merges to master.

提交回复
热议问题