Trying to push a new feature branch, you accidentally branch of staging instead of master.
git cherry-pick can help in this case.
$ git checkout feature/paid-campaign-measurement
This branch has `develop` as its parent. It should have `master`.
$ git log --oneline 37ad159 Remove uneeded comment f671fa7 Added logic for checking whether to insert code cc746b3 Add static class for facebook tracking code b04dc50 Merge branch 'fix/golden-state-warriors-logo' 37a0c7c Fixed warriors logo
This gets me a list of the last few commits. The first three are mine.
$ git status On branch feature/paid-campaign-measurement $ git checkout master $ git pull origin master
I make sure I’m on the right branch.
I’m going to fix this with a cherry-pick.
git rebase is another way to fix it – but I spent two hours thinking about the rebase this morning, and was too nervous to go through with it.
cherry-pick, I know how to do.
git checkout -b feature/facebook-campaign-measurement
This creates a new branch with a pretty similar name.
git cherry-pick --help
Get my syntax, to be sure I know what I’m doing.
$ git cherry-pick cc746b3 [feature/facebook-campaign-measurement fae0a96] Add static class for facebook tracking code Date: Fri Jan 26 11:03:55 2018 -0800 2 files changed, 42 insertions(+) create mode 100644 plugins/msgn/includes/MSGN/Analytics/Facebook.php $ git cherry-pick f671fa7 [feature/facebook-campaign-measurement 4ad13a0] Added logic for checking whether to insert code Date: Fri Jan 26 12:12:28 2018 -0800 2 files changed, 23 insertions(+), 1 deletion(-) $ git cherry-pick 37ad159 [feature/facebook-campaign-measurement b705421] Remove uneeded comment Date: Fri Jan 26 13:57:44 2018 -0800 1 file changed, 10 deletions(-)
I cherry-pick my three commits in the same order I made them.
$ git status On branch feature/facebook-campaign-measurement Untracked files: (use "git add <file>..." to include in what will be committed) ../../plugins/msgn/package-lock.json nothing added to commit but untracked files present (use "git add" to track) $ git push origin feature/facebook-campaign-measurement Counting objects: 27, done. Delta compression using up to 4 threads. Compressing objects: 100% (27/27), done. Writing objects: 100% (27/27), 3.14 KiB | 0 bytes/s, done. Total 27 (delta 16), reused 0 (delta 0) To firstname.lastname@example.org:/msgn.git * [new branch] feature/facebook-campaign-measurement -> feature/facebook-campaign-measurement
Then I cancel the code review on my old branch and request code review on the new one.