Forgot to create new branch. How to transfer changes to new branch

前端 未结 6 2038
闹比i
闹比i 2021-02-19 13:45

this happens to every developer time-to-time. You start coding a new feature and forget to branch first locally.

So if that happens is there a way I can say hey, transf

6条回答
  •  生来不讨喜
    2021-02-19 14:08

    If you have not yet committed:

    Then there is no harm in switching to a new branch after files have been modified. Edited, non-committed files are always viewed in the context of whatever branch is checked out:

    git checkout -b mytopicbranch
    

    If you've already committed:

    Following the description: here:

    1. Create the branch you wished you had made (but don't switch to it):
    git branch mytopicbranch
    

    It now has all the commits that you wanted to make.

    1. Reset the master branch back to before these commits:
    git reset abc5b0de1 --hard
    

    Assuming abc5b0de1 is the fingerprint of the commit right before you made the accidental commits.

    Now you can switch back to mytopicbranch as needed.

提交回复
热议问题