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

后端 未结 4 1904
一向
一向 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:15

    If the first SHA is HEAD you can also use this approach:

    git reset --soft $OLD_SHA; git add -A; git commit --amend --no-edit
    

    be careful, this command will change the history of the repo.

    If you want to squash commits that are in the middle of your history:

    |---* --- 0 --- 1 ---- 2 --- 3 --- * --- * --- * --- HEAD
    

    like in this case the commits 1, 2 and 3

    I would really recommend to use rebase -i

提交回复
热议问题