git - Is there a way to remove commits from one branch and place them into another? -


I made a mistake and mistakenly tried to master for a while, and now I realize my mistake It is, I want to move those people back to the master and go back to their own staging branch.

Is it possible, what to do with GIT or do I manually move files manually?

If your mistakes are those that currently look like a master:

  A-> B->; C- & gt; D   

and you just want to move c and D to a new branch, it is very easy: $ git Checkout Master # D $ transfer to GIT Branch New branch # D $ GIT Reset to create new branch B-SA1 # Reset Master B $ GIT Checkout continues to work on new branch # Based on the changes made by New-branch

C and D , this does not work properly Can, for example, if is the C-class introduces a new file, Git You may not checkout the new branch because of the fear of overwriting the file. (When the master is checked out on B , the guitar thinks that the file has been untracked.) You can add a git clean -xdf after reset Are, or reset to - depending on the circumstances.

Comments