合并后压扁Git提交 [英] Squashing Git commits after merging

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

问题描述

我有一个功能分支,其中有一些提交(请参见下文).自分支以来,一些提交也已添加到master中.

I have a feature branch that has a few commits (see below). Since branching, a few commits have been added to master too.

所以我将master合并到feature分支中.

So I merged master into the feature branch.

git checkout feature
git merge master

这将导致以下feature分支上的日志历史记录:

This results in the below log history on the feature branch:

*    E (HEAD) merging master into feature
|\
| *  D feature commit 2
| |
| *  C feature commit 1
* |  B master commit 2
|/
*    A master commit 1

实际上,特征路径上的提交数量很大(100+),我想将它们全部压缩.

In reality the number of commits on the feature path is large (100+) and I'd like to squash them all.

是否只有在保留master行上的提交时才压榨特征分支上的提交?

Is there a way to just squash the commits on the feature branch only while preserving those on the master line?

推荐答案

可以.因此,您想将问题中的提交图变成这个新图:

Yes you can. So you want to turn the commit graph in your question into this new graph:

*    E (HEAD) merging master into feature
|\
| *  D feature commit (squashes 1 and 2)
* |  B master commit 2
|/
*    A master commit 1

过程:

  1. 确保您的工作树是干净的.没有未提交的更改,没有暂存的更改,没有未跟踪的文件.
  2. 确保您位于要素分支上.
  3. git reset --hard *Hash of D on feature branch*
  4. git reset --soft *Hash of A on master*
  5. git commit,其中包含您想要的消息.
  6. git merge master
  1. Ensure your working tree is clean. No uncommitted changes, no staged changes, no untracked files.
  2. Ensure you are on the feature branch.
  3. git reset --hard *Hash of D on feature branch*
  4. git reset --soft *Hash of A on master*
  5. git commit with the message you desire.
  6. git merge master

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

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