Mark Allison Mark Allison - 3 months ago 11
Git Question

How to branch from n-4 commits, and set n-4 as master?

I should have created a branch called

develop
n-4 commits ago, can I go back and set n-4 to be
master
and create a new branch from that point which includes the last n-4 commits?

I'm using GitExtensions on Windows but happy to do from commandline if easier.

Answer

You can do it using following commands:

git checkout -b develop HEAD
git branch -f master HEAD~4

First one creates a new branch develop. Next just reset the branch master