In this article, we will discuss and show a stepwise method of how to undo or revert a commit command that got executed in GitHub by mistake. It happens generally that we make mistakes and we like to undo or revert the wrong commit to avoid any major issues and correct the mistake by executing the correct commit command.
GitHub
GitHub is an internet hosting service for software development and version control using Git. Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is available for both – Git on Windows & Git on Linux machines. Once Git is installed on the machine you can easily clone a Git repository and can manage it from a local machine via PAT [Personcal Access Token].
The “Commit” Command
Let us suppose a situation when you or someone have to commit the changes under the branch “edledge” and by mistake, you have executed the commit command with an old branch name i.e. “edledge.com“. Since you were on branch “edledge” the commit should have been done under the same branch. Refer to the details below
edledge-git:~/github$ git commit -m edledge.com
[edledge e435475] edledge.com
1 file changed, 131 insertions(+), 3 deletions(-)
In the above situation, it can be easily seen that the user was on branch “edledge” but he committed the changes under branch “edledge.com“
Undo or Revert the “Commit” Command
To undo or revert the commit command, execute the command as shown below.
Check the commit id and use the command shown below to revert the commit. In this situation, we can see above the commit ID was “e435475“
edledge-git:~/github$ git revert e435475
[edledge.com 6e16d16] Revert "edledge"
1 file changed, 66 insertions(+), 12 deletions(-)
rewrite zones/edledge.com.yaml (69%)
Please remember, the revert command will revert the last commit and will rewrite the file. Double check before reverting the commit command.
Other important topics
- How to Install Git on Linux Machines
- How to Install Git on Windows Machines
- How to Clone a Repository from GitHub
- How to Create Personal Access Token [PAT] in GitHub
Source: Knowledge Base, Internet, Github
EA00146