luis.ap.uyen
luis.ap.uyen

Reputation: 1364

Go back two commits but keep the two last in new branch

I want to go back two commits, which would lead to a detached head, with two commits after HEAD. However I would like these two commits to keep them in a new branch, and master pointing to the checked out commit.

How should I do this?

Upvotes: 2

Views: 379

Answers (1)

user43968
user43968

Reputation: 2129

I suppose you are talking about master going 2 commit before Pretty easy stay on master at the tip of your branch. No need to detach head.

D---E---F---G master

Create the new branch git branch myNewBranch

             master
            |
D---E---F---G
            |
            myNewBranch

then reset master two commit before git reset --hard HEAD~2

   master
    |
D---E---F---G
            |
            myNewBranch

Upvotes: 2

Related Questions