Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move Old Commit to New Branch

Tags:

git

branch

I've accidentally started working on a new feature in the middle of another. My repository simply looks like this:

A - B - C - D - E master

But I'm hoping to make it look like this:

A - B - D - E     master
       \
        C         new-feature

It seems like a simple question, but I haven't yet found an answer to it by searching. It seems like cherry-picking is close to what I want, and also maybe some rebasing, but I'm new to Git and some help would be appreciated.

like image 638
bbill Avatar asked Jun 18 '13 00:06

bbill


People also ask

Can you move a commit to another branch?

You can move a commit to another branch using the Git command line.


1 Answers

First, to make the new branch:

git branch new-feature C

Next, to fix up master

git checkout master
git rebase -i B

When the editor comes up, delete C from the list. Save and exit.

like image 83
Carl Norum Avatar answered Sep 24 '22 02:09

Carl Norum