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
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.