Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebase a single Git commit

Tags:

git

rebase

People also ask

Can I rebase a commit?

What is git rebase? From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.

What is rebase onto git?

Rebase is an action in Git that allows you to rewrite commits from one Git branch to another branch. Essentially, Git rebase is deleting commits from one branch and adding them to another.


You can cherry-pick XX to master.

git checkout master
git cherry-pick <commit ID of XX>

And remove the last commit from the feature branch with git reset.

git checkout Feature-branch
git reset --hard HEAD^

git rebase --onto master branch~1 branch 

This says "rebase the range of commits between last-before-branch and branch (that is, XX commit) on the tip of master branch"

After this operation branch tip is moved on commit XX, so you want to set it back with

git checkout branch
git reset --hard branch@{1}^

Which says "reset the branch tip to the commit before its previous state"

So a cherry pick is a simpler solution...


It's pretty simple to do actually. The solution is to do an interactive rebase and "drop" all of the commits you don't want to include in the rebase.

git rebase -i <target_branch> where target_branch is the branch you want to rebase on to

Then you will edit the file that is opened and pick the commits you do want and drop (or d for short) all the commits you don't want to bring along.