Reputation: 243
Suppose that there is commits A, B, C and D and they're all in master branch, so the history looks like this.
A -> B -> C -> D -> HEAD.
C and D brings some features that are not quite tested, and you need to separate them into new branch (which you should've done in the first place), test them, etc. and then merge back.
So how do i revert master to commit B and separate C and D into new branch so the branch tree looks like this?
A -> B -> master's HEAD.
\-> C -> D -> new branch's HEAD.
Upvotes: 0
Views: 1084
Reputation: 60547
Lots of ways. You want a new branch label on D
and the master branch label on B
. There's the way in comments, or this slightly-shorter way:
git branch newbranch
git reset --hard @~2
or this way that leaves you on the new branch, so there's less work tree churn if that's where you're working from:
git checkout -b newbranch
git branch -f master @~2
one note: there's only one HEAD
, it is the parent git commit
will use. As a matter of clarity, branches have tips. HEAD
is usually attached to (i.e. a symbolic link to) whatever you last checked out, committed, or reset to, so when you check out a branch, git sets HEAD
to be a symbolic ref, an alias, for that branch tip.
Upvotes: 1