Search code examples
gitrebase

Rebase a single Git commit


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?


Solution

  • 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^