Skip to content

How can I revert a commit in GitHub after realizing it introduced a bug? #654

Answered by Armiiin
fostira asked this question in Q&A
Discussion options

You must be logged in to vote

If you've made a commit in GitHub that you later realize introduced a bug, you can revert it to restore the previous state of your project. Here’s how to do it:

  1. Identify the Commit: First, you need to find the commit hash of the commit you want to revert. You can do this by running the following command in your terminal:

    git log
    

    This will display a list of commits along with their hashes. Locate the commit that caused the issue.

  2. Revert the Commit: Once you have the commit hash, you can use the git revert command to create a new commit that undoes the changes made by the problematic commit. Run the following command, replacing <commit-hash> with the actual hash:

    git revert <commit-hash>
    

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fostira
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants