Just use git reset without the --hard flag:
git reset HEAD~1
PS: On Unix based systems you can use HEAD^ which is equal to HEAD~1. On Windows HEAD^ will not work because ^ signals a line continuation. So your command prompt will just ask you More?.
manpreet
Best Answer
3 years ago
My issue is I have changed a file eg: README, added a new line 'this for my testing line' and saved the file, then I issued the following commands
I didn't push the code to github, Now I want to cancel this commit.
For this I used
But I lost the newly added line 'this for my testing line' from the README file. This should not happen. I need the content to be there. Is there a way to retain the content and cancel my local commit?