我是 git 的新手。我正在做一个项目,我使用了破坏我项目的新提交。
所以我使用 git log 和 git check out 返回到上次提交。这在我的电脑上是成功的,但是当我尝试将它推送到 github 存储库时,我看到了这个错误:
error: failed to push some refs to 'https://github.com/bamdadghoori/courses.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
bamdad@DESKTOP-MJ4O8KO MINGW64 /e/courses (master)
这些是我尝试过的一些方法
1-重新初始化并使用新的提交
2-使用 git revert
如果这真的是你想要git push --force
做的,那么就应该这样做。请注意,如果您滥用它,它可能会删除您的旧作品。
就像您建议git revert
的那样可能是更好的选择,因为它不会删除或覆盖任何历史记录。
假设您的分支git log
如下所示:
commit 95c374fca46bee52b9fd18e090e6afdfbe73813d (HEAD -> main, origin/main)
Author: Git User <[email protected]>
Date: Fri Mar 19 17:02:49 2021 +0100
Latest commit message
commit 1177cab6490264e922075f28804404f4e1c08f76 (origin/main, main)
Author: Git User <[email protected]>
Date: Wed Mar 17 12:35:33 2021 +0100
Commit message of the one you would like to keep
如果你想恢复最新的提交,你可以这样做git revert HEAD
(HEAD 总是指你的分支的最后一次提交)或者恢复任何提交,你可以复制粘贴提交哈希。在这种情况下git revert 95c374fca46bee52b9fd18e090e6afdfbe73813d
。
然后通过键入ZZ
(注意大写)或:wp
然后按 Enter 来接受可能在 vim 中打开的建议提交消息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句