Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change branch-off point

Tags:

git

I have a branch called feature and it has a few commits. The branch and its commits are still local to my machine (haven't been pushed to a public repository). The graph looks like

A---B---C---D---E---F---G master
                    \
                     P---Q---R feature

Now I realized that I should've made the branch feature off of an earlier commit on master. Let's say commit C. In other words, the graph should look like

A---B---C---D---E---F---G master
         \
          P---Q---R feature

What I am trying to do in essence is revert commits D, E and F out of the feature branch. Yes, I could just revert commits one at a time but there are too many to revert; the above picture is just an illustration.

like image 818
Sri Sankaran Avatar asked Jan 10 '12 12:01

Sri Sankaran


People also ask

How do I switch to a new branch in git?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


1 Answers

What you want to do is a rebase. To pick up the commits P, Q and R and apply them on top of C, you execute:

git rebase --onto C F feature

See the man-page of git-rebase for more information.

like image 86
opqdonut Avatar answered Sep 22 '22 06:09

opqdonut