How to remedy for accidently making a commit into the master branch instead of my feature branch

后端 未结 2 1509
一向
一向 2021-01-28 08:57

Locally, I forgot to create a feature branch from the master branch, and then made a commit of my changes into the master branch.

How can i correct the mistake, so that

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 09:11

    git checkout master
    git checkout -b my-feature-branch
    git checkout master
    git reset --hard HEAD~1
    git checkout my-feature-branch
    

    Explanation:

    1. First we make sure we are on the master branch.
    2. Now we create a new feature branch, bringing along the latest commit.
    3. We move back to the master branch.
    4. We reset the master branch to the commit before the last one.
    5. We go back to the feature branch to continue working on it.

提交回复
热议问题