【发布时间】:2021-05-14 04:39:27
【问题描述】:
我想压缩一些提交,我关注了this 所以我做到了:
git reset --soft HEAD~20
git commit
git push -f
我不知道为什么,但现在我的分支充满了以前没有的合并 我想恢复 git reset --soft HEAD~20 命令 如何做呢? 谢谢!!
更新
我做了:
git reset
然后
git 推送
我得到了:
error: failed to push some refs to 'https://xxxx@bitbucket.org/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获取您希望 HEAD 指向的提交的 sha-1。然后git reset --hard <commit-hash>将您的分支恢复到该提交。 -
为什么我需要“--hard”?我还需要 git push 吗?
-
如果您有任何本地更改并且您不希望在您的存储库中再次进行这些更改,您可以使用 --hard 选项。它只是将 repo 恢复到指定提交时的状态。
-
在 reflog 中重置到该哈希是否解决了您最初的问题?如果是这样,您可以将@meshkati 的答案标记为已接受。
-
仅供参考,请不要忘记尽可能选择
--force-with-lease...