I was working on branch feature1 and accidentally made a new branch feature2 without switching back to master first. Then I added a commit and pushed it to GitHub.
Now a PR that I submitted based on feature2 includes commit D, which it shouldn't.
I want to move feature2 so it's a direct descendant of master and no longer includes commit D.
To illustrate, I want to turn this:
┌─────────────┐ ┌─────┐ ┌─────┐ ┌─────┐
│ master │────▶│ A │───▶│ B │───▶│ C │
└─────────────┘ └─────┘ └─────┘ └─────┘
╲
╲ ┌───────────┐ ┌─────┐
╲──────▶│ feature1 │───▶│ D │
└───────────┘ └─────┘
╲
╲ ┌───────────┐ ┌─────┐
╲───▶│ feature2 │───▶│ E │
└───────────┘ └─────┘
To this:
┌───────────┐ ┌─────┐
╱─────────────────────────────▶│ feature2 │───▶│ E │
╱ └───────────┘ └─────┘
╱
┌─────────────┐ ┌─────┐ ┌─────┐ ┌─────┐
│ master │────▶│ A │───▶│ B │───▶│ C │
└─────────────┘ └─────┘ └─────┘ └─────┘
╲
╲ ┌───────────┐ ┌─────┐
╲──────▶│ feature1 │────▶│ D │
└───────────┘ └─────┘
I read Move the most recent commit(s) to a new branch with Git. I'm sure the answer is in there somewhere, but among the dozens of replies I couldn't find one that seemed accurate and safe for this case.