I have executed the following command
git add <foo.java>
git commit -m "add the foo.java file"
How can I delete my local commit now and unstage foo.java?
If I type git reset --hard, I found that it reverts my modified foo.java to the original one.
git reset --soft HEAD~1should do what you want. After this, you’ll have the first changes in the index (visible withgit diff --cached), and your newest changes not staged.git statuswill then look like this:You can then do
git add foo.javaand commit both changes at once.