0

I accidentally committed to a branch that I didn't realize someone else was working on and my changes are completely incompatible with what they have done. By total coincidence, our branch names just happened to be the same.

I haven't pushed to their branch, but I did commit locally.

I tried doing git rebase --onto some-branch-alt some-branch but I get the error:

fatal: Does not point to a valid commit 'some-branch-alt'

How do I move my commits on some-branch over to a new separate branch some-branch-alt which itself is branched from somewhere completely different from the other author's git branch?

eComEvo
  • 11,669
  • 26
  • 89
  • 145
  • Related, possibly even a dup: https://stackoverflow.com/q/29914052/184546 Presumably, some part of your syntax is incorrect. – TTT Sep 28 '20 at 18:16
  • I assume you already created a branch called some-branch-alt? Then try changing the last word from some-branch to some-branch~x where x is the number of commits you added to some-branch. – TTT Sep 28 '20 at 19:01

1 Answers1

0

Assuming that the commit is the last one on some-branch, to transfer the commit you simply do:

git checkout some-branch-alt
git cherry-pick some-branch

To remove the commit from the old branch, you just redefine it to point to the previous commit:

git branch -f some-branch some-branch~
j6t
  • 9,150
  • 1
  • 15
  • 35