How to undo the most recent commits in Git?

Technology CommunityCategory: GitHow to undo the most recent commits in Git?
VietMX Staff asked 3 years ago
Problem

You accidentally committed wrong files to Git, but haven’t pushed the commit to the server yet. How can you undo those commits from the local repository?

$ git commit -m "Something terribly misguided"      
$ git reset HEAD~                                   # copied the old head to .git/ORIG_HEAD
<< edit files as necessary >>                       
$ git add ...                                       
$ git commit -c ORIG_HEAD                           # will open an editor, which initially contains the