How can I unstage my files again after making a local commit?
git reset --soft HEAD~1
should do what you want. After this, you'll have the first changes in the index (visible with git diff --cached
), and your newest changes not staged. git status
will then look like this:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: foo.java
#
# Changes 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
#
You can then do git add foo.java
and commit both changes at once.
Use:
git reset HEAD^
That does a "mixed" reset by default, which will do what you asked; put foo.java in unstaged, removing the most recent commit.
To me, the following is more readable (thus preferable) way to do it:
git reset HEAD~1
Instead of 1
, there could be any number of commits you want to unstage.
git reset --soft
is just for that: it is like git reset --hard
, but doesn't touch the files.
For unstaging all the files in your last commit -
git reset HEAD~