为什么我不能在 github 中推送还原的提交?

why cant I push reverted commit in github?

我很新 git.I 正在做一个项目,我使用了新的提交破坏了我的项目。

所以我使用了 git 日志和 git 检查以返回到上次 commit.that 在我的计算机上成功但是当我尝试将其推送到 git集线器存储库我看到这个错误:

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 还原

如果这确实是您想要做的,git push --force 应该可以做到。请注意,如果您滥用它,它可能会删除您的旧作品。

就像您建议的那样,git revert 可能是更好的选择,因为它不会删除或覆盖任何历史记录。
假设您的分支 git log 看起来像这样:

commit 95c374fca46bee52b9fd18e090e6afdfbe73813d (HEAD -> main, origin/main)
Author: Git User <git.user@mail.com>
Date:   Fri Mar 19 17:02:49 2021 +0100

    Latest commit message

commit 1177cab6490264e922075f28804404f4e1c08f76 (origin/main, main)
Author: Git User <git.user@mail.com>
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 接受可能在 vim 中打开的建议提交消息,然后按 Enter。