I have royally messed up a branch.
I've been key slamming and have merged/ pulled/ squashed and i don't know what else.
All the work on my feature branch should be in 1 commit
I want to keep where my work is at but I don't want the 10 commit histories.
I can't squash commits anymore as there are conflicts and it's just gotten to be such a mess.
Squashing is no longer and option because git rebase-i HEAD~2 i've done a merge at some point and can't do that - because in the middle of a rebase my changes couldn't be applied because I some how got behind remote by squashing - I must have done it wrong.
So what I would like to do is checkout a new branch and delete all of my commit history prior to the last one.
What is the best way to do this? Also can you please explain the solution like I'm 5 please?
If you have all the files you need on your working directory, you can just erase the current git repository and create a new one:
rm -rf .git
git init
git add .
git commit -m "initial commit"
What you could also do if you wanted to keep the reflog intact is to use reset as a cheap way of rebasing. Find out the hash of your initial commit, reset --mixed to it, keeping all of the changes in your working directory and then commit --amend to add these changes to the initial commit:
# find out the id of your first commit
git rev-list --max-parents=0 --abbrev-commit HEAD
# reset to it
git reset --mixed <first commit id>
# add files to index and amend
git add .
git commit --amend -m "initial commit"