Back

Explore Courses Blog Tutorials Interview Questions
+5 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I have done the following command

git add <foo.java>

git commit -m "add the foo java"

How can I delete my local commit now and make foo.java in an unstaged state?

If I type git reset --hard, I found that it will revert my modify foo.java to the original one.

1 Answer

+5 votes
by (50.2k points)
edited by

For this 

git reset --soft HEAD~1 will do what you need for that you need to first change the index so that the files can be visible with git diff --cached and the changes made in the index are not staged then the git status will look like:

# On branch master

# Changes to be committed:

#   (use "git reset HEAD <file>..." to unstage)

#       modified:   foo.java

# Changes are not staged for commit:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#       modified:   foo.java

For complete understanding of git here is a tutorial that helps you in learning version controlling:

Browse Categories

...