Git squash all commits in branch without conflicting

感情迁移 提交于 2019-12-02 15:51:42
Rasmus Østergaard Kjær Voss

If you don't need the commit information, then you could just do a soft reset. Then files remain as they were and when you commit, this commit will be on top of the commit you did reset to.

To find the commit to reset to:

git merge-base HEAD BRANCH_YOU_BRANCHED_FROM

Then

git reset --soft COMMIT_HASH

Then re-craft the commit, perhaps:

git commit -am 'This is the new re-created one commit'

This is simlar to the answer from Rasmus but broken down into three steps that should always work:

$ git merge feature1
$ git reset --soft HEAD@{1}
$ git commit -c feature1

Explanation:

  1. merge and resolve conflicts
  2. keep changes staged but reset to old head
  3. commit all changes using commit message and author from feature branch latest commit
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!