[英]Git - When branching off BranchA, how do I reset my new branch BranchB so it doesn't have any BranchA content?
[英]I accidentally run `git branch <branchA> <branchB> -f` and can't go back to previous state
我不小心运行git branch <branchA> <branchB> -f
并且无法将 go 返回到之前的 state... 结果,我收到了太多的更改...
我最初在很久以前创建的一个分支中使用 Draw.io 编写了架构。 当我认为是时候合并它时,我做不到,因为我收到以下消息。
There isn't anything to compare. master and document/initial-architecture are entirely different commit histories.
所以我看了这个 URL( 没有什么可比较的。没有什么可比较的,分支是完全不同的提交历史)。
所以我运行了以下代码。
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 reflog
的结果。
git reflog
可能会拯救你,如果你从那以后没有做太多的动作。
git reflog
显示你的动作而不是你的分支历史,找到最后一个好地方的 SHA 和git reset --hard _YOUR_SHA_
。
YMMV。
git branch -f branchA branchA@{1}
请参阅git help revisions
中的 reflog 语法。
@{1} 语法是类似这样的 oopses 的非常普遍的回退。
Shell 历史扩展(由!
引入)有一个“当前行”标记#
和一个“最后一个词”选择器$
,使得这里完全不需要重复分支名称的速记
git branch -f branchA !#$@{1}
我太喜欢了,更不用说了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.