Frage

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.

War es hilfreich?

Lösung

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)

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top