Reputation: 3273
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?
Upvotes: 135
Views: 233363
Reputation: 2955
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.
Upvotes: 0
Reputation: 1323883
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:
you can easily revert a pull request on GitHub by clicking Revert:
You'll be prompted to create a new pull request with the reverted changes:
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.
Upvotes: 74
Reputation: 1191
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.
Upvotes: 21
Reputation: 822
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
After
REVERT
, do not forget toPUSH
the code. For more details, check the link How to restore deleted files on GitHub website?
Upvotes: 10
Reputation: 323
This worked for me (GITHUB).
1) git reset --hard HEAD^
2) git push origin -f
Note:- These lines reverts commit back one by one.
Upvotes: 2