git merge后清理--no-ff

时间:2013-12-22 21:58:33

标签: git

两个分支 - masterfeature - 与git merge --no-ff合并。后来的feature分支被删除了。树看起来像那样:

*      (master) A new feature added to the master
|\
| *        yet another small commit
| *        another small commit 
| *        small commit
|/
*      Master before the feature was added

我想从树中清除那些小提交,看起来像:

*      (master) A new feature added to the master
*      Master before the feature was added

怎么做?当地的回购还没有推出。

2 个答案:

答案 0 :(得分:4)

我愿意

git checkout master
git reset --soft <HASH of commit "Master before the feature was added">
git commit -m "A new feature added to the master"

或者你可以使用

git commit -c ORIG_HEAD

重用原始合并提交中的提交消息。

答案 1 :(得分:2)

让我们假设您的仓库看起来像这样(我需要提交SHA)

*   82daefb - (HEAD, master) A new feature added to the master (15 seconds ago) 
|\  
| * 6e156b0 -  yet another small commit (84 seconds ago) 
| * ccc4753 - another small commit (2 minutes ago) 
| * e76a659 - small commit (2 minutes ago) 
|/  
* 3041679 - Master before the feature was added (2 minutes ago) 
  1. 恢复您的功能分支 git checkout -b feature && git reset --hard 6e156b0
  2. 将maser重置为 3041679 git co master && git reset --hard 3041679
  3. 合并您的分支git merge feature --squash
  4. 提交合并git commit -m "A new feature added to the master"
  5. 最后你的树看起来像

    * 6bf734c - (HEAD, master) A new feature added to the master (68 seconds ago)
    * 3041679 - Master before the feature was added (5 minutes ago)