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

huangapple go评论65阅读模式
英文:

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

以下是翻译好的部分:

  1. 将用户“nullptr”上面的评论是正确的。

  2. 我会添加一些细节,以帮助避免一些混淆。

  3. 检出“main”分支,以便HEAD指向主分支,并创建新分支将指向那里。

    git checkout main

  4. 创建新分支以保存之前的主分支状态。在我的示例中,我将其称为“save-old-main”。

    git checkout -b save-old-main

  5. 现在,您可以使用“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.

  1. 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

  1. 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

  1. 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

huangapple
  • 本文由 发表于 2023年4月17日 17:46:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定