Git:如何挤压合并提交之间的提交? [英] Git: How to squash commits which have merge-commit in between?

查看:163
本文介绍了Git:如何挤压合并提交之间的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 进行了多次提交。压扁提交。

  2. 将更改推送到远程分支。有冲突。

  3. 合并主要更改,功能分支上已解决的冲突。 (git fetch origin master> git merge FETCH_HEAD>手动解决了冲突> git commit> git push)
  4. 我做了一个更多的提交

因此,当前的提交历史记录如下所示。
从当前到旧:
$ b


  1. 提交3

  2. 提交M yyy(合并)

  3. 提交2

在合并我的特性之前,我如何压扁3以上提交到1分支去掌握?

解决方案

您可以< rebase -i code> commit 2 的父节点(也就是你分支的 master )的提交。当你到达合并提交时解决冲突。



因此,如果您的历史记录看起来像

  * D提交3(HEAD)
* M合并
/ |
| * C提交2
* | B提交master
| /
* A(master)

> git rebase - 我会看到 master your_branch 的提交列表,但不是合并提交。 pick 第一个( B C ,取决于时间)和 squash 其余。


I am working on a feature branch.

  1. Made several commits. Squashed commits.
  2. Pushed changes to remote branch. Got conflicts.
  3. Merged changes from master, resolved conflicts on feature branch. (git fetch origin master > git merge FETCH_HEAD > resolved conflicts manually > git commit > git push)
  4. I made one more commit.

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

  1. commit 3
  2. commit M yyy (Merged)
  3. commit 2

How do I squash above 3 commits into 1 before I merge my feature branch to 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)

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.

这篇关于Git:如何挤压合并提交之间的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆