英文:
Github - How do I go back to a commit which is 3 pull requests in the past and then restore the main branch as to that commit
问题
我想要能够将主分支还原到一个提交点,就像它在之前的三次合并之前的状态一样。另外,虽然这不是非常重要,但我想保留在那个提交点之后进行的所有更改(这三次合并),并将它们存储在另一个分支(或分支)中。基本上就是将主分支还原到过去的状态,同时保留在此之后进行的更改。如果可以使用GitHub Web界面来完成这个操作,那就太好了。
英文:
I want to be able to restore the main branch to a commit, as how is was 3 merges before. Also, although its not really important, I would like to keep all the changes that were done after that commit (the 3 merges) and store them in another branch (or branches). So basically just restoring the main branch as to how it was in the past whilst also keeping the changes that were made after. And if this can be done using the GitHub web ui that would be great.
答案1
得分: 0
以下是翻译好的部分:
-
将用户“nullptr”上面的评论是正确的。
-
我会添加一些细节,以帮助避免一些混淆。
-
检出“main”分支,以便HEAD指向主分支,并创建新分支将指向那里。
git checkout main
-
创建新分支以保存之前的主分支状态。在我的示例中,我将其称为“save-old-main”。
git checkout -b save-old-main
-
现在,您可以使用“branch”命令来重置主分支。重要的是,在执行此操作时,您当前的分支不应为主分支,因为不允许对您已检出的分支执行此操作。
git branch -f main hash-you-want-main-at
英文:
The comment from user "nullptr" above is correct.
I would add a couple of details to help avoid some confusion.
- Checkout the "main" branch so that HEAD is pointing to the main branch, and the creation of the new branch will point there.
git checkout main
- create the new branch to save the previous state of main. I'm calling it save-old-main in my example.
git checkout -b save-old-main
-
You can now use the "branch" command to reset main. It is important that you do not have main as your current branch when you do this, because it is not allowed to do this to the branch you have checked out.
git branch -f main hash-you-want-main-at
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论