简体   繁体   English

如何将我的 GitHub 提交恢复到前一个?

[英]How to revert back my GitHub commit to the previous one?

I have a private GitHub repository.我有一个私有的 GitHub 存储库。 I only push to the main branch and I'm the only person with access to the repository.我只推送到主分支,并且我是唯一有权访问存储库的人。

在此处输入图像描述

I would like to bring back things as they were 4 days ago (to the commit on Dec 5, 2020) and that last commit (5 hours ago) to disappear.我想恢复 4 天前的内容(到 2020 年 12 月 5 日的提交)并且最后一次提交(5 小时前)消失。

I used the following commands when I pushed to git.我在推送到 git 时使用了以下命令。

   git add notes.org
   git commit -m "Sync"
   git push

I would be grateful for any suggestion.我将不胜感激任何建议。 Thank you!谢谢!

To remove all traces of the new commit, you need to reset your branch back to an earlier state (commit) that doesn't include that.要删除新提交的所有痕迹,您需要将分支重置回不包含该内容的早期 state(提交)。 If you're just removing the first most recent commit, you could do如果您只是删除第一个最近的提交,您可以这样做

# switch to your branch
git switch your-branch

# reset your branch hard to point to the (1) most recent commit
git reset --hard your-branch~1

# push the new state of your branch to the server forcefully
git push your-remote your-branch --force-with-lease

You can use the following two commands to remove the last commit on your end, and force github to match yours.您可以使用以下两个命令删除最后一次提交,并强制 github 与您的匹配。

git reset --hard HEAD^
git push origin -f

If the second command does not work, try如果第二个命令不起作用,请尝试

git push --force origin main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM