How not to be afraid
I would like to show you that no matter how bad you feel, commits are never destroyed *, and you can always go back to where you started.
I created a faux git tree that has the same shape as you:
Now I'm going to destroy the last three commits from the backup branch:
$ git log --oneline 9b41f46 Removed extraneous whitespace 981e2e8 Merged the "loadscripts" function 005bc62 Pick up a few very fringe cases 07e71d9 Merged "getDepsForScript" function ... $ git reset --hard HEAD~3 HEAD is now at 07e71d9 Merged "getDepsForScript" function $ git log --oneline 07e71d9 Merged "getDepsForScript" function ...
Unfortunately, that was bad. Go back to where we started. First, let's see what we did:
$git reflog 07e71d9 HEAD@{0}: HEAD~3: updating HEAD 9b41f46 HEAD@{1}: commit: Removed extraneous whitespace ...
You can see that when we reset, all git did this so that HEAD would point to this old commit. But no commits were actually lost - they simply became orphans, and not part of any industry. Let them become part of the "backup" branch again:
$ git reset --hard 9b41f46 HEAD is now at 9b41f46 Removed extraneous whitespace $ git log --oneline 9b41f46 Removed extraneous whitespace 981e2e8 Merged the "loadscripts" function 005bc62 Pick up a few very fringe cases 07e71d9 Merged "getDepsForScript" function ...
Git means you didn’t have to say you were sorry.
* Free objects eventually collect garbage, but only until they are at least two weeks old.
How to do what you want.
First merge the two commits into a master:
$ git checkout master $ git rebase -i HEAD~2
Git will launch your editor. Change this:
pick 6389f4e Moved "loaded" function out of "require". pick 41fb646 comma
:
pick 6389f4e Moved "loaded" function out of "require". s 41fb646 comma
And save it. git will launch your editor again. Change this:
:
Moved "loaded" function out of "require".
and save.
Now reorder the commits to 'backup':
$ git checkout backup $ git rebase -i remotes/origin/master
When your editor appears, change this:
pick ec7f71c moved "loaded" function out of "require" pick 4a76897 Replaced maploaded event pick 07e71d9 Merged "getDepsForScript" function pick 005bc62 Pick up a few very fringe cases pick 981e2e8 Merged the "loadscripts" function pick 9b41f46 Removed extraneous whitespace <-----
:
pick 9b41f46 Removed extraneous whitespace <----- pick ec7f71c moved "loaded" function out of "require" pick 4a76897 Replaced maploaded event pick 07e71d9 Merged "getDepsForScript" function pick 005bc62 Pick up a few very fringe cases pick 981e2e8 Merged the "loadscripts" function
and save.
Now cherry - select the combined "Moved download" that completes the wizard and to the current branch ("backup")
$git cherry-pick master
Make a master point for the same commit as the backup
$git checkout master $git reset --hard backup
Get rid of the twist branch
$git branch -D twist