Just to confirm: this is what you've done:
Start working from point 5:
1 ... 2 ... 3 ... 4 ... (5) ... 6 ... 7 ... 8
Pull 5-8 off into a branch:
1 ... 2 ... 3 ... 4 ... 5 ... 6 ... 7 ... 8 (master)
\ ... 5 ... 6 ... 7 ... 8 (work)
And now you want master to look like this:
1 ... 2 ... 3 ... 4 (master)
\ ... 5 ... 6 ... 7 ... 8 (work)
If that's so, here's how you can do it
locally (read disclaimer below!!)
1. Switch branch to master:
git checkout master2. Reset master to the state in commit 4:
git reset --hard 4 (where 4 is the actual commit ID of commit "4")
DIsclaimer:
This deletes commits! You should generally never do this on a remote repository (though it's fine to do locally). To make origin/master reflect your local master, you'll have to do
git push -f, which you've probably heard a million times is a Bad Idea. It'll piss off any collaborators you have royally.
But if it's your own repository and nobody else is sharing it with you, you could consider doing that. It's reversible as long as you don't run
git gc haphazardly (just
git reset --hard back to the original state, you can use
git reflog to help you find its ID)
SECOND disclaimer:
Only do this if I'm right about the assumptions I've listed!