Summary: I forgot to switch branches when developing and would like to move the files/changes to the appropriate branch.
Details: I have two files A
and B
which are initially in master
. I then created a branch branch1
to make some breaking changes in file A
.
While developing these changes I also modified B
and created a file C
. The problem is that I now realize I made a mistake with branching and that
B
should be in its own branch2
(which does not exist), C
belongs in master
. All of them are now commited in branch1
.
The commits were pushed to a remote repository but it does not matter that much, I can have the other developer clone the repo (as opposed to fetch).
What is the general methodology to recover in such a case, ie. to move files or changes between branches?
A simple solution is, from where you are on branch1
:
git checkout -b branch2
), and remove C
. Add, commit, and pushC
from branch1
(git show branch1:path/to/C >path/to/C
). Add, commit and push.branch1
, remove the extra files, add, commit and push.That way, no merge, no history rewrite, not even a revert, just some additional commits pushed to remote to cleanup the current situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With