Rebase Any String of Commits to a Target Commit If topic is not checked out, you simply append topic to the command (except the last one) like so: git rebase -onto B master topicĪlternatively, check out the branch first with: git checkout topic I'm leaving this answer here in case someone comes here with a case like mine.The correct command to answer the posted question could be any of the following (assuming branch topic is already checked out): git rebase -onto B master The rebase completed with no issues, and no merge conflicts. To solve this issue, I added the -i option to be able to edit the todo list, and just dropped the commits that I did not want. When I tried to rebase (following the instructions in answer) the two commits I wanted from branch B, I ended up with the two commits, plus a bunch of new commits coming from merging stage into B, and this was giving me unwanted merge conflicts during the rebase. I made the mistake of merging stage into A, and B, because I thought that they sharing the tip o stage would help makes things easier. I wanted the last two commits of branch B to be placed in branch A.īoth branches, A and B, were now behind stage because stage had gotten other branches merged into it. Branch A had a single commit not in stage, and branch B had 3 commits not in stage. I had a similar situation, where 2 branches had branched off of the same stage branch at different points in history. Note that the d and c commits here are copies (they have new unique ids) that's inevitable when you move commits around, as commits themselves are immutable. After that, reset br up to where master is now, and then slide master back down to where it was before c: % git rebase -onto br e7547cb master The harder case is that the other branch already exists: let's say it's br in the first graph above. If not, then simply make the new branch here (where master is now) and slide master back down to before c: % git branch newbranch Does that other branch already exist or not? So I can think of two main scenarios here. So I regret that c and d were made on master I wish they had been on some other branch. Let's start with a two-branch situation: % git log -oneline -all -graph You can move a branch, attaching it to any commit you like, with git reset. Though I am interested to hear solutions for both scenarios (this one, and one where I had other valid commits). So obviously I'm a bit new to git and I'm sure this has got to be a duplicate question, but maybe I am just having trouble identifying which existing questions are the duplicates with confidence.Īlso I tagged vs 20 because I use both and welcome any answers that explain how to do this through the IDE in either of those versions in additions to how to accomplish this in a shell. It's very possible I've run across the exact answer I need, but didn't realize it because I wasn't 100% if the scenario was the same as mine. I've done some searching and the answers I've found primarily focus on the first case I mentioned where changes weren't committed. or I want to be able to restore them (as changes, but not as a commit, obviously). And when I checkout the branch I want, I want my changes to be there. I just want the commit to go away as if it never happened. in particular I don't want to have to push two commits (one with the changes, and one that reverts the changes). I want my local branch to be as though I never made any changes. How do I effectively accomplish the same thing if I've already committed locally (but not pushed to remote)? Normally if I make changes in a branch and realize I meant to do it in a different branch, then I can simply stash the changes and then checkout the branch I want.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |