Undoing One Single Commit
Undoing the last (local-only) bad Git commit needs this command:
This will move the current branch back to the second last commit and store the committed changes in the Index. To reuse the commit message for the next commit, you will have to remember it.
git reset --soft HEAD~ Undoing Multiple Commits
To undo multiple last (local-only) commits, use this command (using the commit ID of the commit that should become HEAD):
This will store all differences between the previous and the new HEAD into the Index.
git reset --soft <commit> Considerations
- If you have already pushed your bad commits, they are now part of the remote repository. In that case, undoing commits might not be advisable, as other users may have already based their commits on them. If you still wish to undo the bad commits, you will need to force-push the current branch.