How can I squash a range of git commits together given starting and ending SHA's

后端 未结 4 1895
一向
一向 2021-02-07 03:19

I have a branch with about 20 commits.

The first SHA on the branch is bc3c488...
The last SHA on the branch is 2c2be6...

How can I

4条回答
  •  无人及你
    2021-02-07 04:07

    The first SHA on the branch is bc3c488...
    The last SHA on the branch is 2c2be6...

    # non dangerous implementation that creates a new branch.
    git checkout 2c2be6
    git rebase -i bc3c488~
    git checkout -b your_new_squashed_branch
    # then squash the commits by replacing the pick with s
    

    The tilda (~) at the end of the commit means previous commit;
    Ensuring commit bc3c488 is visible on the interactive rebase.

    # dangerous implementation that rewrites history
    git checkout -b new_branch_with_rewritten_history
    git reset --hard 2c2be6
    git rebase -i bc3c488~
    # then squash the commits by replacing the pick with s
    

提交回复
热议问题