2016-02-22 48 views
0

我想清理一个开发分支。有一个分支由多个提交创建,包括将开发分支合并回功能分支。然后功能分支合并到开发中。壁球n提交到一个,当n包括合并

所以在发展,我有一些提交:

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

我想粉碎前4个提交到一个承诺。但不管我尝试的东西因为合并而被搞砸了。由于在开发分支上执行的合并工作被粉碎成feature1提交。

是否粉碎了这些提交可能?

编辑,使用重订如下尝试:

当我尝试 'git的变基-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 

但是,这个问题是我压扁提交'squash b44463a合并分支开发到feature1',我不想这样做。因为该合并包含合并到feature1分支的开发分支中的工作。我想让这个提交看起来像只是feature1的东西。

如果我在重新绑定时删除合并行,它将失败。

+0

你尝试过git squash吗? – CodeWizard

+0

@codeWizard我有。我认为我遇到的问题是,在合并中挤压不属于特征的提交。这是因为合并将开发分支更改拉到feature1分支。 – lostintranslation

+0

尝试按照答案,看看它的工作, – CodeWizard

回答

2

它看起来像你要的那样从feature1工作中分解开发合并,为此,您要将三个提交功能压缩到一起,然后分离合并。

请在交互式数据库编辑器中尝试以下顺序。

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

太棒了!没有考虑重新订购,那是关键。 – lostintranslation

0

为了做一个git壁球遵循这些步骤:

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

一旦壁球你的提交 - 选择s为壁球=将所有提交合并成一个单一的提交。

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.` 
+0

请参阅编辑。这是我已经尝试过的。由于开发合并到feature1中,因此不会仅压缩feature1更改。 – lostintranslation