2

I started working on a new feature on master, by creating a commit A:

o -- A  (master)

before realizing that I should probably create a new branch. However, I didn't "move" the commit A to the new branch, so now my repo looks like this:

o -- A (master)
      \ 
       B - C - D - E (feature)

Luckily, I did not push to remote, nor are there any commits after o on master. How to move A from master to feature branch, and make my history look like this:

o (master)
 \
  A - B - C - D - E (feature)
1

1 Answer 1

2

Since a branch is just a pointer with new commits stacked on top of the original, you can do this:

First, make sure you are on master,

git checkout master

Then point master back at the origin by doing this (make sure you don't have any uncommitted changes as this will wipe them):

git reset --hard HEAD~1

And that should be it. You can check master with git log and then check your feature branch by doing

git checkout feature
git log

Not the answer you're looking for? Browse other questions tagged or ask your own question.