I was working on a simple project recently and ended up doing a bunch of work straight on master. Not a good idea, don't do it. But of course you already know all about using feature branches. Alas, that is the situation I found myself in.
Running the usual
git rebase -i master did not make sense to me as I was on master, and running
git rebase -i resulted in a edit screen opening but, there were no commits listed to squash, only the word
Of course I searched for what this means but, other than this short thread, there really wasn't anything. I was stumped and saw a ton of cherry picking in my future to get all of these commits into an actual feature branch that I can then rebase against master.
Luckily for me I work with some really awesome people who are git ninjas and it was not long before willkg commented on my pull request and told me exactly how to put my woes to rest. So, here is what you need to do:
Now find the SHA of the commit (it will look something like
commit 00a621eeea97060d57dd83d957e3504df849da73) just before your first commit to master or, the commit where you should have branched. Now run:
This will now open the interactive editor, show the list of commits, and allow you to squash, edit, and remove to your hearts content. I sincerely hope you are never in such a situation but, if you are, now you know how to get out of it.