Git newbie here, thanks in advance for the help: I've done the following:
- Create a new branch from tag v1.9 (I called it MyBranch1.9)
- Make some edits, commit them, and sync to the remote branch
- Create a new branch from an earlier tag v1.8 (called MyBranch1.8)
I'd like to get to the following result:
- The edits I made (#2 above) end up in MyBranch1.8
- Edits made by others (the ones between tags v1.8 and v1.9) do NOT end up in MyBranch1.8. Effectively, I'd like to backport just the changes I made to MyBranch1.8.
May I ask how to make Git do this? I've tried rebasing interactively but it seems to try and bring all the commits in MyBranch1.9 to MyBranch1.8.
Super bonus points if you could please share the git command line syntax as I'm new to this. Thanks!
CodePudding user response:
The documentation for this comes straight out of the git rebase
man page:
Here is how you would transplant a topic branch based on one branch to another, to pretend that you forked the topic branch from the latter branch, using rebase --onto.
First let's assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.
o---o---o---o---o master \ o---o---o---o---o next \ o---o---o topic
We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this:
o---o---o---o---o master | \ | o'--o'--o' topic \ o---o---o---o---o next
We can get this using the following command:
git rebase --onto master next topic
So for your specific situation, you would want:
git checkout MyBranch1.9
git rebase --onto v1.8 <base> MyBranch1.9
Where <base>
is the name of whatever branch you forked MyBranch1.9
from. You'll probably want to replace your old MyBranch1.8
branch at
this point:
git branch -D MyBranch1.8
git branch -m MyBranch1.9 MyBranch1.8
Note that I've been assuming here that you haven't made any changes in
the MyBranch1.8
branch.