How to Not Be Afraid
I'd like to show you that no matter how bad you mess up, commits never get destroyed* and you can always get back to where you started.
I've made a faux git tree that has the same shape as you illustrated:
I am now going to wipe out 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
...
Oops, that was bad. Let's get back to where we started. First 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 was to make HEAD point to that old commit. But no commits were actually lost--they just became orphans, not part of any branch. Let's make them 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 never having to say you're sorry.
*Loose objects do eventually get garbage collected, but not until they are at least two weeks old.
How to Do What You Want.
First let's combine the two commits in 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
to this:
pick 6389f4e Moved "loaded" function out of "require".
s 41fb646 comma
And save. Git will again launch your editor. Change this:
# This is a combination of two commits.
# The first commit's message is:
Moved "loaded" function out of "require".
# This is the 2nd commit message:
comma
to this:
Moved "loaded" function out of "require".
and save.
Now let's reorder the commits in 'backup':
$ git checkout backup
$ git rebase -i remotes/origin/master
When your editor pops up, change this:
pick ec7f71c moved "loaded" fucntion 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 <-----
to this:
pick 9b41f46 Removed extraneous whitespace <-----
pick ec7f71c moved "loaded" fucntion 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-pick the merged "Moved loaded" commit off of master and onto the current branch ("backup")
$git cherry-pick master
Make master point to the same commit as "backup"
$git checkout master
$git reset --hard backup
Get rid of the twist branch
$git branch -D twist