Reputation: 59
Occasionally I commit work only to later realize that it would have been better off in it's own branch.
Hindsight is 20/20 and if I was thinking ahead I would have made a new branch and then committed onto that sparing me this problem in the first place.
Is it possible to move an existing commit onto a new Branch? If so, how is it done? and can it be achieved through Visual Studio?
Upvotes: 5
Views: 8435
Reputation: 28954
It can be done in Visual Studio. Here are the steps:
You now will be in the exact same situation as if you created the new branch in the first place.
Side note: I do recommend learning how to do this from the command line rather than using the GUI. Once you know it, it's faster, easier, doesn't tie you to any particular UI, and enables you to script your favorite workflows more easily. As an example, here's the same workflow from the command line:
git branch new-branch-name
# create new branch like what's checked out nowgit reset --hard HEAD~1
# go back one commit (change 1 to however many you need)git checkout new-branch-name
Upvotes: 4