Keeping the Changes (Soft Reset)
If you want to undo the commit but keep the changes in your working directory for further modification, you can use a soft reset:
git reset --soft HEAD~1
- `HEAD~1` refers to the commit immediately before the latest one.
- `–soft` moves the current branch back by one commit but leaves your files as they were before the commit. The changes from the commit will remain staged, allowing you to modify them as needed.
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