Move all changes/commits from current branch to a different branch

58 Views Asked by At

I was modifying some code in a team repo and mistakenly made all my changes in the 'master' branch when I should have been working in the 'Development' branch. I committed my changes before I realized this, but I'm not able to push changes directly to master.

So I need to move all my commits to Development, push them, and then discard all the changes on master.

Is there a straightforward way of doing this? I was thinking 'rebase Master into Development' but I'm not 100% sure about that. I'm using VS and the built-in git GUI tools.

1

There are 1 best solutions below

3
TorusWithSprinkles On

Okay after comparing a lot of different methods this is what wound up working perfectly for my situation:

  1. Checkout/switch to Development (the branch where I want my commits)
  2. In console: "git cherry-pick commit1 commit2 commit3" - where commit1 is the oldest (first) commit that I want and commit3 is the newest
  3. Checkout/switch back to master
  4. Reset --hard to the last commit that you want to keep, discards all changes