【问题标题】:I accidentally run `git branch <branchA> <branchB> -f` and can't go back to previous state我不小心运行了 `git branch <branch> <branch Of` 并且无法回到之前的状态
【发布时间】:2023-01-17 01:05:17
【问题描述】:

我不小心运行了git branch &lt;branchA&gt; &lt;branchB&gt; -f,无法回到之前的状态... 结果,我收到了太多的变化......

我最初是在很久以前创建的一个分支中使用 Draw.io 编写架构的。当我认为是时候合并它时,我做不到,因为我收到以下消息。

There isn't anything to compare. master and document/initial-architecture are entirely different commit histories.

所以我查看了这个 URL (There isn't anything to compare. Nothing to compare, branches are entirely different commit histories)。

所以我运行了以下代码。

81906@DESKTOP-608QNA0 MINGW64 ~/Documents/slackbot-gpt3 (document/initial-architecture)
$ git branch master document/initial-architecture -f

81906@DESKTOP-608QNA0 MINGW64 ~/Documents/slackbot-gpt3 (document/initial-architecture)
$ git checkout master
Switched to branch 'master
Your branch and 'origin/master' have diverged,
and have 25 and 28 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

81906@DESKTOP-608QNA0 MINGW64 ~/Documents/slackbot-gpt3 (master)
$ git push origin master -f
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Cannot force-push to this protected branch
To https://github.com/Suchica/slackgpt3.git
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/Suchica/slackgpt3.git'.

在这里,发生了 37 处更改,我想撤消它们,但我不知道该怎么做。 Git 图看起来像这样。

【问题讨论】:

    标签: git github


    【解决方案1】:

    git reflog 如果你从那以后没有做太多的动作,可能会救你。

    git reflog显示你的动作而不是你的分支历史,找到最后一个好地方的SHA和git reset --hard _YOUR_SHA_

    YMMV。

    【讨论】:

      猜你喜欢
      • 2018-10-18
      • 2012-04-17
      • 1970-01-01
      • 2017-12-07
      • 2023-02-22
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      相关资源
      最近更新 更多