Git: Squashing consecutive commits that are not the most recent commits, and do not start at the root

主宰稳场 提交于 2019-11-28 10:26:00

First of all, if F---G---H are squashed, then I---J would be I'---J'.

Given that, I'd create a branch first then use vanilla git reset then git cherry-pick:

# D---E---F---G---H---I---J master
  1. git checkout -b work H

    create branch work at H

  2. git reset E

    now work is at E

  3. git commit -am "F-G-H squeezed as Z"

    commit the changes done by F---G---H as Z

  4. git cherry-pick I^..J

    take over I---J

Now the work branch is in the shape you want, just reset master to it:

# D---E---Z---I`---J` work

git checkout master
git reset work
git branch -d work

Note: the commit range has been corrected to I^..J, to represent the commit series I---J (from I to J, inclusive).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!