我可以直接在 GitHub 上恢复提交吗?

看起来你可以直接在 GitHub 上使用网页界面做任何事情,比如编辑、创建和删除文件,但是我无法找到一种方法来恢复提交,就像你可以在 GitHub 本地应用程序(Windows 和 Mac)上做的那样,就像你可以在 git 命令行上做的那样。

我只是在想我是不是漏掉了什么,还原按钮是不是藏起来了?

我试着在网上搜索,发现了一些东西,似乎表明这是为了防止在与许多人一起工作时出现同步错误。是这样吗?

147952 次浏览

No, that feature isn't directly available on the GitHub web interface (as opposed to the "Revert" button recently added for GitHub for Mac/Windows)

Actually, it is for pull requests only, since June 24th, 2014:

Introducing the Revert Button

you can easily revert a pull request on GitHub by clicking Revert:

https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67

You'll be prompted to create a new pull request with the reverted changes:

https://camo.githubusercontent.com/973efae3cc2764fc1353885a6a45b9a518d9b78b/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6e65772d70722e706e67


git revert is a bit more complex to manage through the web as it can accept a range of commits.
It shouldn't be an issue in terms of collaboration though: a revert adds a new commit, it doesn't change the history of existing commits.

This worked for me (GITHUB).

 1) git reset --hard HEAD^
2) git push origin -f

Note:- These lines reverts commit back one by one.

You can't revert back to that commit on the GitHub web site, there is no option to do this action, Instead, you should use command-line or GitHub Desktop as below

enter image description here

After REVERT, do not forget to PUSH the code. For more details, check the link How to restore deleted files on GitHub website?

If you want to use just github web. There is a tedious way though.

Step 1. Goto commit history, find the commit hash which you want to revert to; and click "Browse repo at this point in history"

Step 2. Create a new branch from this commit hash (say "temp")

Step 3. Delete the branch which had the problem (say "main")

Step 4. Goto "temp" branch and create "main" branch from it. And you're done.

Ofcourse, this is not a good way and it might only work for recently created commits.