如何压缩之间具有合并提交的提交?

问题描述:

我正在开发功能分支.

  1. 进行了几次提交.压缩提交.
  2. 将更改推送到远程分支.有冲突.
  3. 合并了来自主节点的更改,解决了功能分支上的冲突.
    • git获取原始主文件
    • git merge FETCH_HEAD
    • 已解决的手动冲突.
    • git commit
    • git push

因此,当前的提交历史看起来像这样.从最新到旧:

So, current commit history looks like this. From current to old:

  1. 提交3
  2. 提交M yyy(合并)
  3. 提交2

在将功能分支合并到master之前,如何将3以上的提交压缩为1?

How do I squash above 3 commits into 1 before I merge my feature branch to master?

您可以 rebase -i commit 2 的父级开始(即,在分支的 master .当您到达合并提交时,您可能必须重新解决冲突.

You can rebase -i starting with commit 2's parent (that is, the commit on master that you branched from. You'll likely have to re-resolve conflicts when you get to the merge commit.

所以,如果您的历史记录看起来像

So if your history looks like

  * D commit 3 (HEAD)
  * M merge
 /|
| * C commit 2
* | B commit on master
|/
* A (master)

git rebase -i A 开头.您会看到一个提交列表,包括 master your_branch ,但没有合并提交. pick 第一个(根据时间的不同,选择 B C ),其余部分使用壁球.

Start with git rebase -i A. You'll see a list of commits including both master and your_branch, but not the merge commit. pick the first one (B or C, depending on timing) and squash the rest.