Handling Pushed Commits
If the commit has already been pushed to a remote repository, you will need to handle the remote history separately, typically involving a force push. This should be done with caution to avoid disrupting others’ work.
After performing the reset locally, force push to the remote repository:
git push origin HEAD --force
Warning: Force-pushing rewrites history on the remote branch, which can affect collaborators. Always communicate with your team before doing this.
How to Delete Local Commit in Git?
Deleting a local commit in Git can be done in a few ways, depending on whether the commit is the most recent one or if it is further back in the commit history. Here’s an article on how to delete a local commit in Git, tailored to whether you want to keep the changes made in the commit or discard them entirely:
Table of Content
- Keeping the Changes (Soft Reset)
- Discarding the Changes (Hard Reset)
- Handling Pushed Commits
- Deleting a Specific Commit (Using git reflog and cherry-pick)
- Summary