If you have accidentally committed the wrong files into Git, but haven’t yet pushed it to the server, you can recover, or undo your commit as follows:
How to Undo a Commit and Redo it
You have just committed a file, and find yourself here;
We will call this “your accident location”.
Start by resetting:
Now you can edit your files as required.
When you are done, run the following commands:
A note on Step 2
Step 2 said to use
git reset HEAD~
HEAD~ is the same as
HEAD~1, which can allow you to undo a certain amount of commits. As we only stipulated
1 or simply
~, it only undid 1 place.
Swap this out for a greater number if you want to undo a larger amount of commits.