0

Currently I have two branchs: Master and Dev. In the last week I commited my work on branch Master (branch wrong) and now I need to change these commits to the DEV branch (right branch), what better way to do this?

Im using github desktop on MAC

Cheers, Rafael

Rafael C.
  • 2,245
  • 4
  • 29
  • 45

3 Answers3

0

Your question is unclear. So I am assuming you need your old version of master, and you need your new version of Dev. This means you will need to change your git history. If you have pushed these commits to your remote, this is not what you should be doing, as you don't want to be messing with git history.

What you do is cherry-pick the commits from master, and then reset your master to before the commits.

Before you do that, you should backup your data:

git checkout master
git checkout -b backup_master
git checkout DEV
git checkout -b backup_DEV

How to cherry pick: How to cherry-pick multiple commits

Community
  • 1
  • 1
Bryce Drew
  • 5,777
  • 1
  • 15
  • 27
0

My thought was to use patching to avoid possibly conflicts.

git checkout master
git format-patch -1 HEAD (if thats all you want)
git checkout dev
git apply —check file.patch (check it first)
git am < file.patch

Replace HEAD with the SHA HASH for the oldest commit you would want and then it will create a *.patch for each commit to current. Then apply them to dev in the proper order singly.

Then you could checkout master again, change to the commit before the ones you don't want on master by checking out that SHA hash. Then commit it back with a good message. I think that might do it. Please correct me if I misunderstood or if I'm blatantly wrong guys.

ddaypunk
  • 1
  • 1
  • 2
0

If you have pushed these commits to your remote , You can not remove commit from MASTER branch.

you can do one thing fetch the latest MASTER Branch code to DEV Branch.

for that : back up you DEV branch git checkout -b backup_DEV then :

git checkout DEV

git stash

git rebase MASTER

git push DEV 

git stash pop

Now you can see that commit in DEV.

dr. strange
  • 665
  • 7
  • 22