Reputation: 213
I have over-engineered myself into a corner. The two things that need to happen are:
How do I revert back to an earlier working version of my code?...and simultaneously,
How do I then create a separate branch to save that code while still having a saved version of my new code to draw from?
Any help is greatly appreciated
Upvotes: 3
Views: 50
Reputation: 124646
Before switching branches, if you have pending changes, commit them.
If you know the commit SHA you want to go back to, you can create a new branch from it and switch to it:
git checkout -b <new_branch_name> SHA
Upvotes: 2
Reputation: 589
Note down the SHA of the last commit (say e123asd)
To remove last commit from branch 1
git reset --hard HEAD^
Switch to branch 2
git cherry-pick e123asd
This will bring the last commit to this new branch.
Upvotes: 1
Reputation: 106430
If you know the commit SHA you want to go back to:
git reset <SHA>
git checkout -b <new_branch_name>
Upvotes: 2