0

It is similar to Make the current git branch a master branch but a bit different.

I have made some commits in master, but now they wont be used, I want to keep them in the future, turning it into a new branch, I want to get a old commit and merge some features (like cherry-pick) and then make this the current master.

      .----------E (no branch)
     /          /
----A---B---C---D (master)

Version D is the current master, and I want E to be the one. I am doing this way:

git checkout A
git merge --no-commit --no-ff D
# do some changes here
git commit -m 'message for E'

This generate a no branch commit, I was wondering how to turn this into master and turn B, C and D a new branch.

The difference for the answer above is that I do not want E to be the new branch, I want it to be named master, and change the others to a new branch.

Community
  • 1
  • 1
Tiago Pimenta
  • 736
  • 7
  • 20
  • 1
    Do you really want `E` to have all the changes from `B-C-D`? – Alexey Ten Feb 12 '14 at 12:48
  • @alexeyten it is not all of them, but it is boring doing cherry-pick of several commits, it is easier to undo some of them by `git reset file; git checkout file` – Tiago Pimenta Feb 12 '14 at 12:54
  • I solved part of the the problem creating a new branch and moving them: `git checkout -b test; git -m master new-feated-issues; git -m test master` now how to do it for the remote issue? – Tiago Pimenta Feb 12 '14 at 13:07

2 Answers2

1

Just like the post you linked to, this should only be done if you haven't pushed master anywhere.

First, create a new branch from master with git branch new-branch master. You should end up with

      .----------E (no branch)
     /          /
----A---B---C---D (master) (new-branch)

Now, move master to E with

git checkout master
git reset --hard E

Your final network should look something like

      .----------E (master)
     /          /
----A---B---C---D (new-branch)
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
0

This command will create new branch pointed to D.

git branch new-branch D

This will set you current branch tip to commit A while all changes will stay in place:

git reset --soft A
# do some changes here
git commit -m 'message for E'

These commands will not create merge commit as in your example, but I guess that you don't need it.

Alexey Ten
  • 13,794
  • 6
  • 44
  • 54