How to Revert a Commit Already Pushed to a Remote Repository
Posted By : Kamaldeep Singh | 31-Dec-2015
In this blog I would like to tell you how to revert your last commit from git hub. There may be a case when you realize that one of the commits should not be there, or that there was some unacceptable typo in it. So that isn't a big problem. All you need to take care of is that you should do it fast before anyone fetches the bad commits.
This can be done in two ways :-
- Correct the mistake in a new commit
- Revert the full commit
Correct the mistake in a new commit
This is simple as you just need to remove or fix the bad file in a new commit and push it to the remote repository. This is the most natural way to fix an error, always safe and totally non-destructive, and how you should do it 99% of the time. Yet the bad commit remains there and accessible, but this is usually not a big deal.
Revert the full commit
In this case, instead of going through all the changes manually your whole previous commit will be reverted. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it. To do this, first reset the branch to the parent of the current commit, then force-push it to the remote as follows.
$git reset HEAD^ --hard $git push -f
For more details, Click Here
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Kamaldeep Singh
Kamaldeep is a bright Groovy and Grails Sr. lead Developer, And has experience in development of various SAAS application using Java J2EE. He likes to listen music and Net Surfing.