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

 You accidentally committed the wrong files to Git, but you haven't pushed the commit to the server yet.

How can you undo those commits from the local repository?



First, before we bring the big guns in, let's make sure you really need them. Because in case you just want to edit your last commit, you can simply use Git's amend feature. It allows you to correct the last commit's message as well as add more changes to it. If that's what you want to do


steps to follow


1- The fist step it's your commit before to think to revert (the moment when you commit wrong things)

2- Reset will rewind your current HEAD branch to the specified revision. In our example above, we'd like to return to the one before the current revision - effectively making our last commit undone.

git reset head explain

3- Make corrections to working tree files.

4- Add anything that you want to include in your new commit.

5- Commit the changes

Comments