[英]How do I revert back to a former Git commit and then save it in a separate branch?
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 任何帮助是极大的赞赏
If you know the commit SHA you want to go back to: 如果您知道要返回的提交SHA:
git reset <SHA>
git checkout -b <new_branch_name>
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: 如果您知道要返回的提交SHA,可以从中创建一个新分支并切换到它:
git checkout -b <new_branch_name> SHA
Note down the SHA of the last commit (say e123asd) 记下最后一次提交的SHA(比如e123asd)
To remove last commit from branch 1 从分支1中删除最后一次提交
git reset --hard HEAD^
Switch to branch 2 切换到分支2
git cherry-pick e123asd
This will bring the last commit to this new branch. 这将使最后一次提交到这个新分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.