git 合并后的清理 --no-ff

  • 本文关键字:--no-ff 合并 git 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

怎么做?本地回购尚未推送。

我会做的

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

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

假设你的存储库看起来像这样(我需要提交 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. 将激射重置为3041679 git co master && git reset --hard 3041679
  3. 合并分支git merge feature --squash
  4. 提交合并git commit -m "A new feature added to the master"

最后你的树会看起来像

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

最新更新