Remove the last commit from the remote git repository
In this short article, show you how to remove the last commit from the git repository.
Checkout more articles on Git
Here, we will see three simple steps to remove the last commit from the local and remote git repository.
Steps to remove the last commit from the remote git repository
1. Check the logs
First of all, check your local commit with messages before removing the last commit. Run the following command to check the logs in one line.
1 | git log --oneline |
2. Remove the last commit from the local branch
Now, Run the following command to remove the last commit and discard the changes from the local branch.
1 | git reset --hard HEAD~1 |
Checkout the different ways to Undo commit before push in Git.
3. Update remote repository
At last, we will update the files and again need to push with force. It will delete the previous commit and keep a new one on the remote git repository.
1 | git push origin <name_of_branch> -f |
Now you can check the logs to verify the commit in the git repository.
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂