To create the slave commit, do:
git checkout <b-sha1> --orphan slave
git commit -C <b-sha1>
Then to remove the old b commit, do:
git rebase --onto <a-sha1> <b-sha1> master
Note that you can only do the second step if you have not pushed b-sha1
yet, as you should never rewrite history for pushed commits.
Also note that the contents of the snapshot of commit c will now be different, because it will not have any of the changes from commit b anymore (well technically in your example they wouldn't be, since you are doing empty commits, but if they were "real" commits they would be). If that is not what you want, then instead of doing git rebase --onto
, do an interactive rebase:
git checkout master
git rebase -i <a-sha1>
Your editor will pop up with something like the following:
pick <b-sha1> Commit message for B
pick <c-sha1> Commit message for C
Copy the commit message for C, and change the contents of the file to:
r <b-sha1> Commit message for B
f <c-sha1> Commit message for C
Close your editor, and a new editor will pop up with the commit message for B; replace that with the commit message for C, and close the editor. Then you're done.