Rebase a single Git commit

Kevin Meyer picture Kevin Meyer · Jan 31, 2013 · Viewed 75.3k times · Source

Is there a way to rebase a single commit from a branch onto another branch?

I have this branch structure:

-- -- -- -- -- (Master)
            \
              -- -- -- -- -- XX (Feature-branch)

All I want to do is to rebase the last commit of Feature-branch onto master and rollback Feature-branch one commit.

-- -- -- -- -- XX (Master)
            \
              -- -- -- -- -- (Feature-branch)

How do I do that?

Answer

tewe picture tewe · Jan 31, 2013

You can cherry-pick XX to master.

git checkout master
git cherry-pick <commit ID of XX>

And remove the last commit from the feature branch with git reset.

git checkout Feature-branch
git reset --hard HEAD^