I branched from master a week ago.
master -> my_branch_1
During this time I've made commits to my_branch_1 and also rebased on origin/master several times to keep up.
State of the branches ATM (conceptualised)
commit0
master -> my_branch_1
master:
commit1
commit3
commit10
my_branch_1 (commits from master are marked with *)
commit1*
commit2
commit3*
commit4...commit9
commit10
The problem appear when I attempt to open a PR back into master. PR log show all commits 1...10, while I expect only commits 2, 4...9 would appear.
-- EDIT --
Clarification on the origin discussion in comments. The intention was to receive commits that happened on master into my branch.
This was the desired outcome as I wanted to stay as close to "master" as possible to keep in sync with the rest of the code base.
What I don't want is to have these commits that are already in master appear in my PR that I'm doing into master
-- EDIT 2 --
This issue is with a private repo, hosted on GitHub. Not a forked repo.
What have I done wrong?
It sounds like you pulled from origin/master rather than rebasing, at least to get commit3.
How should I fix this?
First, create a backup branch from your branch in case you screw things up. You can do that just by making a new branch from your current one. If you're in the branch you're working on, for example, you can:
git checkout -b my_branch_1_backup
to create a new branch, and then just checkout to get back to your working branch:
git checkout my_branch_1
Second, rebase again. I'd start by doing an interactive rebase and just removing the commits you don't want. Use the -i flag to rebase interactively, like:
git rebase -I commit1
This will give you a list of commits going back to commit1 that you can edit, like:
pick commit2
pick commit3
pick commit4
and so on. If you don't want commit3 (because it's already in master), change pick commit3 to drop commit3. There will be a list of other options in a comment in your editor. Once you've fixed up your list of commits, save and exit the editor, and do a:
git log
You should see that the log reflects your changes.
Finally, you can rebase to origin/master, which will make git get any new commits in master and then add your commits on top of the ones from master:
git rebase origin/master
Check the log again and you should see the commits from master in your log, but before the commits you added in your branch.
At that point, your pull request should include only the commits you added in your branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With