当n包含合并时,Squash n提交为一个

时间:2016-02-22 19:23:06

标签: git merge

我正在尝试清理开发分支。这个分支创建了一个分支,有多个提交,包括将开发分支合并回功能分支。然后将功能分支合并到开发中。

所以在开发中我有一些提交:

"Some commit"
"More commit"
"merge branch development into feature1"
"Another commit - start of feature work"
"First commit that does not include feature1"

我想将前4个提交粉碎成一个提交。但无论我尝试什么东西都因为合并而搞砸了。由于在开发分支上执行的合并工作被粉碎到feature1 commit。

粉碎那些可能的提交?

编辑,尝试使用rebase,如下所示:

当我尝试git rebase -i HEAD~4'我得到以下内容:

pick 3e217ba Another commit - start of feature work
pick b44463a merge branch development into feature1
pick 625ba76 More commit
pick 996b98e Some commit 

我可以将其更改为

pick 3e217ba Another commit - start of feature work
squash b44463a merge branch development into feature1
squash 625ba76 More commit
squash 996b98e Some commit 

然而,问题是我正在压缩提交'压缩b44463a合并分支开发到feature1'这是我不想做的。因为该合并包含已合并到feature1分支的开发分支的工作。我想让这个提交看起来像只是feature1的东西。

如果在重新定位时删除合并行,则会失败。

2 个答案:

答案 0 :(得分:2)

看起来你想要从feature1工作中分解开发合并,为此你想要将三个提交作为特征工作压缩在一起,然后将合并分开。

在交互式rebase编辑器中尝试以下顺序。

pick 3e217ba Another commit - start of feature work
squash 625ba76 More commit
squash 996b98e Some commit 
pick b44463a merge branch development into feature1

答案 1 :(得分:0)

为了做一个git squash,请按照以下步骤操作:

// X is the number of commits you wish to squash
git rebase -i HEAD~X

一旦你压缩你的提交 - 选择s进行squash =它会将所有提交合并为一个提交。

enter image description here

如果需要,还有--root标志

尝试:git rebase -i --root

- root

Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.

This allows you to rebase the root commit(s) on a branch.  
When used with --onto, it will skip changes already contained in `<newbase>`   
(instead of `<upstream>`) whereas without --onto it will operate on every 
change. When used together with both --onto and --preserve-merges, all root 
commits will be rewritten to have `<newbase>` as parent instead.`