I accidentally committed the wrong files to Git but haven’t pushed the commit to the server yet.
How do I undo those commits from the local repository?
Undo a commit & redo $ git -m \”Something terribly misguided\” # (0: Your Accident) # # (1) # === If you just want to undo the commit, stop here! ==>= [ edit files as necessary ] # (3) $ $ (git commit–c ORIG_HEAD # (4) .\n\nThe undo command is git reset. It will delete your last commit while leaving your working tree (the state of your files on disk) untouched. You need to add them again before you can commit them to a new commit. Remit the log message from the old commit and re-c ORIG_HEAD; make corrections to work tree files. If you don\’t have to edit the message, you may use the -C option.\n\nAlternatively, to edit the previous commit (or just its commit message), commit –amend — will add changes within the current index to the past commit; to remove (not revert) a commit that has been pushed into the server with git push — — and to delete (advanced) — to push (to delete) the commit, if it is to be done by — with — an attempt to force.\n\nIf you amend a commit that has already been published, you should know the implications of rewriting history.\n\nFurther Reading You can find the SHA-1 for the commit to which you want to revert using git reflog. Once you have this, use the sequence of commands described above.\n\nHEAD is the same as the one in hEAD 1. The article What\’s the \’HEAD\’ of git is useful if you want to uncommit more than one commit.