简体   繁体   中英

Cleaning after git merge --no-ff

Two branches - master and feature - were merged with git merge --no-ff . Later feature branch was removed. The tree looks like that:

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

I would like to cleanup those small commits from the tree so it looks like:

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

How to do that? The local repo was not yet pushed.

I would do

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"

Alternatively you could use

git commit -c ORIG_HEAD

to reuse the commit message from your original merge commit.

Let's assume that your repo looks like this (I need commits SHAs)

*   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. Recover your feature branch git checkout -b feature && git reset --hard 6e156b0
  2. Reset maser to 3041679 git co master && git reset --hard 3041679
  3. Merge your branches git merge feature --squash
  4. Commit merge git commit -m "A new feature added to the master"

finally your tree will look like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM