为什么我不能在 github 中推送恢复的提交?

巴米

我是 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

Wischm0pp

如果这真的是你想要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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么我不能在 Flatlist 中显示我的项目?

为什么我不能在 init 中获得我的 fetchedResults?

为什么我必须做“ git push”才能在github上查看提交?

为什么我不能将我的 Laravel 项目推送到 github

为什么我不能在异步方法中调试代码?

为什么我不能在 chartjs 图表中更新宽高比?

为什么我不能在 html 中全屏显示图像?

为什么我不能在 css 中对图像进行过渡?

ElasticSearch:为什么我不能在特定类型中搜索?

为什么我不能在JUnit中定义期望的ParseException?

为什么我不能在addEventListener中调用类函数

为什么我不能在ggplot中居中调整标题?

为什么我不能在Java中传递这样的数组

Java:为什么我不能在Comparator中抛出异常?

为什么我不能在 Postgres 中修改列类型

为什么我不能在熊猫函数中应用shift?

为什么我不能在Python中更改类的属性

为什么我不能在回调中调用useRef?

为什么我的线性渐变不能在Firefox中工作?

为什么我不能在GWTP的UiBinder中清除FlexTable?

为什么我不能在Notepad ++中更改文本背景

为什么我不能在Mirth中访问xml消息?

为什么我不能在sqlite中创建视图?

为什么我不能在定义中定义变量?

为什么我不能在iframe中嵌入特定的网址?

为什么我不能在Java中创建ComboBoxes数组?

为什么我不能在python中创建轮子?

为什么我不能在Word 2003中删除水印?

为什么我不能在RStudio中安装“预测”包?