How do I undo the last commit that I haven't pushed yet? #7
|
Hi! I am following the tutorial (Phase 3: Git Branching & Merging). I made a commit locally, but I realized I made a mistake in it. I haven't pushed it to GitHub yet. How can I undo this commit so that I can fix the files and commit again? Should I use |
Answered by
muhammedadnank
Jun 2, 2026
Replies: 1 comment
|
To undo your last local commit (that hasn't been pushed to GitHub yet), you can use the 1. Undo the commit but KEEP your changes (Recommended)If you want to keep the work you did in the files so you can edit and commit them again, run: git reset --soft HEAD~1 |
0 replies
Answer selected by
muhammedadnank
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To undo your last local commit (that hasn't been pushed to GitHub yet), you can use the
git resetcommand. There are two main ways to do this depending on what you want to do with your changes:1. Undo the commit but KEEP your changes (Recommended)
If you want to keep the work you did in the files so you can edit and commit them again, run: