141

It seems like you can do just about everything else directly on GitHub using the web interface, like edit and create and delete files, but I am unable to find a way to revert a commit, like you can in the GitHub local apps (Windows, and Mac) and like you can do on the git command line.

I'm just wondering am I just missing something. Is the revert button hidden?

I tried searching online and came across something that seemed to suggest that this was to prevent synchronization errors when working with lots of people. Is this correct?

5 Answers 5

78

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.

Sign up to request clarification or add additional context in comments.

19 Comments

Geez, this is a nightmare. I saved a few broken versions before I caught the error, and I need to trash them, they're garbage and I don't want them around causing trouble at all. And apparently, I'm stuck with them. Great system.
Sorry, I don't know what most of those words mean. Moving to GitHub was probably a bad idea, I just wanted to post my code publicly and track versions as I worked on it, but this feels like trying to use a howitzer to swat a fly. I've been googling for about an hour now trying to solve this "problem", I can't understand why it's this hard.
Ouch! I'll have take a whole tutorial, which involves diving down into the command line, just to get rid of a simple change to a text file? (And that IBM page seems to be about a completely unrelated topic, near as I can tell? Some sort of proprietary backup system documentation?) I appreciate the effort to help, but I don't think Github can possibly be for what I thought it was for, it just seems too counterproductive. I just wanted to open-source my code & save subsequent versions as I work. But not at cost of needing an engineering degree to accomplish simple tasks like reverting a mistake.
This whole thing is too complicated. I feel like I need TextEdit and all there is is Emacs. I don't want to learn a whole new lingo and set of abstract concepts, I just wanted to share my code on a popular, accessible platform. Gonna bail now, the site is kvetching that this should go into chat & that wasn't my intent. I appreciate the attempts to help.
GitHub needs to add this feature. Why isn't it already there??
|
23

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.

5 Comments

"Revert a commit" is different from "Revert to a commit" Your answer is a nice way for "Revert to a commit"
Theoretically, reverting to n-1 commit, is same as reverting n commit. No? I know the answer is a different approach, but it still helps I guess. But, I agree with you.
Not quite. Reverting to n-1 commit (in git this is actually called "reseting to") means deleting the n commit as if it never happened. Reverting the n commit means creating a new n+1 commit that makes all the opposite changes that n commit did.
I agree this is not a fun way to do it, but still appreciate this answer.
I can't imagine this approach works well in any nontrivial team environment. "Hey guys, where'd the main branch go?". Or even worse, "where'd main and all the commits I just pushed to it go?".
11

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?

1 Comment

Screenshot is from Github Desktop
3

This worked for me (GITHUB).

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

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

9 Comments

This is actually something else than reverting a commit - this is discarding it completely (rewrites history).
This should be marked as the accepted answer.
If you are publishing to a remote repo that other people will be using you should think twice before using this. This is not reverting, this overwriting and is pretty dangerous. Definitely very seldom the correct answer (maybe only for a personal project).
glad to know that it helped.
This should definitely not be marked as the answer. "Revert" means something specific in git and this answer does not do that. The very fact that the OP is using GitHub means it's a shared repo. Using the commands in this answer would have nasty side-effects. And the OP is asking for a button in the UI, not a git command.
|
1

It really depends on how the repo is set up and how much of the history you want to keep.

You can delete the commit by using this and deleting the line with the commit you don't want. This could also mess up histories of other people. People usually don't know git well enough to do git reset --hard origin/main so I'd not recommend it.

git rebase HEAD^1 -i # do stuff git push origin main -f # absolutely playing with fire here 

On PRs there's a revert button that creates as revert PR to undo all the changes in that PR which is pretty useful. It has a downside where if you want to push the same changes again, just fixed instead of broken, you'll have to put them all back in again, revert the revert, delete both and merge again or reimplement the changes by using a combo of git checkout branch-with-changes, git reset --soft branch-without-changes, git stash, git checkout main, git checkout second-try and git stash pop`.

Currently on my team we're doing reverts with the Github gui, then reverting the revert and cancelling the CI/CD manually. This leaves the main broken but since we deploy on "production" it's fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.