How can I merge many commits, but leave one out?

前端 未结 5 637
醉话见心
醉话见心 2020-12-07 19:37

Suppose I have this feature branch \"foo\". Now I want to merge it back into master, but I\'ve added some debugging code that I don\'t want in master.

The debug cod

5条回答
  •  时光取名叫无心
    2020-12-07 20:43

    Another idea is to add the reverted commit of the one with debug code and to merge it into your master branch. Afterwards we remove that extra commit in the foo branch.

    git checkout foo
    git revert COMMIT_REF_WITH_DEBUG_CODE
    
    git checkout master
    git merge foo
    
    git checkout foo
    git reset --hard HEAD~1
    

    Make sure your working tree is clean. First create the reverted commit. Then merge it into master. Afterwards reset the branch pointer of the foo branch to the parent of the reverted commit, so it's back in its original state.

    If you dislike using git reset then you could create a temporary branch where you create the reverted commit. At the end you delete the temporary branch.

提交回复
热议问题