Rebase problem.

I have made two commits into wrong branch. What I’d like to do, but don’t want to break something is to remove these two commits and put them into correct branch.

What I have done is:

git checkout -b newbranch origin/release/xyz

I have SHA1 commit checksums. What I found is that I should start rebasing from the one commit before. But It is not explained why, so I am not entirely sure abut that. What should be the next step?

1 Like

Interesting question.

The git rebase command documentation has some good diagrams that should help make things more clear. If you’ve created a new branch, named newbranch, that contains only the new commits that you want to move, you should be able to issue the command:

git rebase branch-where-you-wanted-the-commits-in-the-first-place newbranch

Then you can merge those new commits into the branch where you wanted them originally with the command:

git checkout branch-where-you-wanted-the-commits-in-the-first-place
git merge --ff newbranch

The --ff option is to ensure that you rebased things right and isn’t strictly necessary. You can then delete the newbranch branch and continue on as you would have originally.

I hope that helps!

3 Likes