0

I have a git branch (A) with work in it. A user committed some additional work into A, when he should have created another branch (B) . I want to have one branch without the additional work in it and one with the user's changes in it.

  • 1
    Does this answer your question? [How to fix committing to the wrong Git branch?](https://stackoverflow.com/questions/2941517/how-to-fix-committing-to-the-wrong-git-branch) – Liam Feb 04 '21 at 16:10
  • 1
    There are multiple, multiple duplicates of this question – Liam Feb 04 '21 at 16:11
  • @Liam The one you referenced isn't the same question. That only involves one branch, this involves two sets of commits and two branches. If the commits are not in the right order that won't work at all – Joe Phillips Feb 04 '21 at 16:16
  • @Randolph It's important to know how the commits are laid out. Are the B commits all at the top of the branch or are they intermixed with the A commits? – Joe Phillips Feb 04 '21 at 16:16

1 Answers1

0

If I understand correctly, you want to separate some later changes to a branch into a completely separate branch? This is what I would do. Branch name: a. Last revision I want to keep in a is X. All later revisions from X will be in branch B. Base branch is main:

git checkout --detach # detach your working tree from all branches
git branch B A # put branch B where A is right now
git branch -f A X # put A where X is
git rebase --onto main A B

Voila!

eftshift0
  • 26,375
  • 3
  • 36
  • 60