How do I undo the most recent local commits in Git?

Ask a question+

I accidentally committed the wrong files to Git, but I haven’t pushed the commit to the server yet.

How can I undo those commits from the local repository?

add comment

1 Answer


To remove the last commit from git, you can simply run git reset —hard HEAD^ If you are removing multiple commits from the top, you can run git reset —hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

nandhini 55
add comment

Your Answer