git - 如何恢复/取消 git reset --soft HEAD~20

标签 git revert git-reset

我想压缩一些提交,然后我关注了 this 所以我这么做了:

git reset --soft HEAD~20
git commit
git push -f

我不知道为什么,但现在我的分支充满了以前没有的 merge 我想恢复 git reset --soft HEAD~20 命令 如何做呢? 谢谢!!

更新
我做了: git reset < 重置前提交哈希:移动到 HEAD~20 > 那么
git 推送 我得到:

error: failed to push some refs to 'https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1169696969517378657364727a74653f7e6376" rel="noreferrer noopener nofollow">[email protected]</a>/xxxx/xxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

最佳答案

运行:

git reflog

它会向您显示如下内容:

0475497 (HEAD -> master) HEAD@{0}: reset: moving to HEAD~20
ab155bc HEAD@{1}: commit: commit before reset
5da1f69 HEAD@{2}: commit: commit message
c2d9604 HEAD@{3}: commit: commit message
.
.
.

然后,您可以使用其提交哈希(在上面的示例中为 ab155bc )来 checkout 或重置到重置之前的提交

关于git - 如何恢复/取消 git reset --soft HEAD~20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66137796/

相关文章:

git - Git 最好的可视化 merge 工具是什么?

git - 如何仅在子目录中运行 husky 预提交

mercurial - 使用 hg revert 恢复 Mercurial 中的一组文件

Git 恢复、 checkout 和重置傻瓜式教程

Git - 撤消 Team Explorer Visual Studio 上的提交

Git:在最新提交之前还原功能分支中的所有提交

Git 提交消息 : 50/72 Formatting

git - 在 merge 到 develop/master 之前是否需要更新 git 分支?

git - 在其他提交完成后从 git rebased 分支中删除提交

git - 恢复到特定的 sha 或提交