-1

I accidentally made two commits on my master branch and now I want to rebase them both onto a new branch.

Here you can see the initial situation...

-- -- -- C1 C2 (master)
       \
        (new-feature-branch)

...and how it should look in the end:

-- -- -- (master)
       \
         C1 C2 (new-feature-branch)

Thanks for youre help

  • 1
    https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard Regret Type 3. – matt Sep 27 '22 at 09:17

2 Answers2

1

Just move the pointers around

git branch temp new-feature-branch # create a temp pointer where master is
git checkout new-feature-branch
git reset --hard master # set feature where master is
git branch -f master temp # set master where new-feature-branch was
git branch -D temp
eftshift0
  • 26,375
  • 3
  • 36
  • 60
0

I'm assuming your history looks like this (correct me if I'm wrong):

-- -- (new-feature-branch) -- C1 C2 (master)

In that case, fast-forward merge the feature branch, then re-create master:

git checkout new-feature-branch
git merge --ff-only master
git branch -f master HEAD~2 # set back 2 commits (adapt if it needs to be moved back by more commits)
knittl
  • 246,190
  • 53
  • 318
  • 364