hello! to revert a commit in a GitHub repository all you have to do is,
i. identify the commit to revert: find the commit hash of the commit you want to revert. you can do this by viewing the commit history either on GitHub or locally.
ii. revert the commit using the GitHub interface: on the GitHub repository page, click on the "Commits" tab and find the commit you want to revert. click on the commit to view its details and then click the "Revert" button. this will create a new commit that undoes the changes introduced by the selected commit.
iii. revert the commit locally and push the changes: if you prefer to revert the commit locally you can use git commands. first checkout the branch where the commit exists. then use the command git revert to create a new commit that undoes the changes. and finally push the changes to the repository.
iv. push the changes: if you reverted the commit locally, don't forget to push the changes to the GitHub repository.
if there's anything else you want to know and clarify let me know. : )
Revert commit on Website
How do I revert a commit in a GitHub repository?
How to use Git Revert - Stack Overflow
revert to previous commit on github?
Videos
git revert makes a new commit
git revert simply creates a new commit that is the opposite of an existing commit.
It leaves the files in the same state as if the commit that has been reverted never existed. For example, consider the following simple example:
$ cd /tmp/example
$ git init
Initialized empty Git repository in /tmp/example/.git/
$ echo "Initial text" > README.md
$ git add README.md
$ git commit -m "initial commit"
[master (root-commit) 3f7522e] initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ echo "bad update" > README.md
$ git commit -am "bad update"
[master a1b9870] bad update
1 file changed, 1 insertion(+), 1 deletion(-)
In this example the commit history has two commits and the last one is a mistake. Using git revert:
$ git revert HEAD
[master 1db4eeb] Revert "bad update"
1 file changed, 1 insertion(+), 1 deletion(-)
There will be 3 commits in the log:
$ git log --oneline
1db4eeb Revert "bad update"
a1b9870 bad update
3f7522e initial commit
So there is a consistent history of what has happened, yet the files are as if the bad update never occurred:
$ cat README.md
Initial text
It doesn't matter where in the history the commit to be reverted is (in the above example, the last commit is reverted - any commit can be reverted).
Closing questions
do you have to do something else after?
A git revert is just another commit, so e.g. push to the remote so that other users can pull/fetch/merge the changes and you're done.
Do you have to commit the changes revert made or does revert directly commit to the repo?
git revert is a commit - there are no extra steps assuming reverting a single commit is what you wanted to do.
Obviously, you'll need to push again and probably announce your balls-up to the team.
Indeed - if the remote is in an unstable state - communicating to the rest of the team that they need to pull to get the fix (the reverting commit) would be the right thing to do :).
Use Git revert like so:
git revert <insert bad commit hash here>
git revert creates a new commit with the changes that are rolled back. git reset erases your Git history instead of making a new commit.
The steps after are the same as any other commit.
Hi, I would like to revert to a previous commit. I believe I did this correctly on my local repository using git reset --hard commit-hash. I would like to push this to github but of this results in
error: failed to push some refs to 'https://github.com/shmish/smartmark.git' hint: Updates were rejected because the tip of your current branch is behind
I am the only working on this repository, so I am not worried about conflicts, I am trying to move back one commit.
git reset --hard <old-commit-id>
git push -f <remote-name> <branch-name>
Note: As written in comments below, Using this is dangerous in a collaborative environment: you're rewriting history
To undo the most recent commit I do this:
First:
git log
get the very latest SHA id to undo.
git revert SHA
That will create a new commit that does the exact opposite of your commit. Then you can push this new commit to bring your app to the state it was before, and your git history will show these changes accordingly.
This is good for an immediate redo of something you just committed, which I find is more often the case for me.
As Mike metioned, you can also do this:
git revert HEAD