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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With