Accidentally pushed a commit to your GitHub repository that you'd like to undo? Don't worry, you can revert a commit even after pushing it. Here's a step-by-step guide on how to revert a commit after pushing it on GitHub.
Understanding Git Revert
Before we dive into the process, let's understand what 'revert' means in Git. A revert is not the same as a reset. When you revert a commit, Git creates a new commit that undoes the changes introduced by the original commit. In contrast, a reset moves the current branch's HEAD to a specific commit, changing the commit history.
Reverting a Commit After Push: The Long Way
If you've already pushed your commit, you'll need to force push your changes. This can potentially overwrite changes others have made, so it's crucial to communicate with your team before proceeding.

1. Find the Commit Hash
First, you need to find the hash of the commit you want to revert. You can do this using the git log command in your terminal.
2. Create a Revert Commit
Once you have the commit hash, you can create a revert commit using the following command:
git revert

This will open a text editor where you can modify the commit message for your revert commit.
3. Force Push Your Changes
After creating the revert commit, you'll need to force push your changes to GitHub. Use the following command:
git push origin --force

Note: Force pushing can overwrite changes others have made, so use it sparingly and communicate with your team.
Reverting a Commit After Push: The Easy Way
If you're using GitHub's web interface, you can revert a commit with just a few clicks.
1. Navigate to Your Repository
Go to your repository's page on GitHub. You should see a list of commits in the 'Commits' tab.
2. Find the Commit You Want to Revert
Scroll through the list of commits until you find the one you want to revert.
3. Click 'Revert This Commit'
Next to the commit, you should see a button labeled 'Revert This Commit'. Click it.
4. Choose 'Create a Revert Commit'
You'll be presented with two options: 'Create a revert commit' and 'Start a new branch for your revert commit'. If you want to keep your commit history clean, choose the first option.
5. Edit the Commit Message
You'll be taken to a page where you can edit the commit message for your revert commit. Make any necessary changes, then click 'Commit revert'.
6. Push Your Changes
Finally, you'll need to push your changes to GitHub. You can do this by clicking the green 'Push origin' button.
Conclusion
Reverting a commit after pushing it can be a straightforward process, whether you're using Git in your terminal or GitHub's web interface. Just remember to communicate with your team if you're force pushing changes, and always be careful when modifying your commit history.






















