I made a mistake and accidentally was committing to master for a while, and now that I’ve realized my mistake, I want to move those commit off of the master and back into my own staging branch.
Is this possible, to do with git or am I going to have to manually move files around?
If your mistakes are such that master currently looks like:
and you just want to move
CandDto a new branch, it’s pretty easy:Depending on what changes are introduced by
CandD, this may not work cleanly. For example, ifCintroduces a new file, git may not let you do the checkout of new-branch for fear of overwriting the file. (When master is checked out atB, git thinks the file is untracked.) You could add agit clean -xdfafter the reset, or doreset --harddepending on the circumstances.