Removing changes from the staging area

It happens that you add changes to the staging area, then you realize they fit better in a future commit, not in the commit you are composing right now.

To remove those changes to one or more files from the staging area, you can use the git reset HEAD <file> command; get back the shell and follow me.

Check the repository current status:

[16] ~/grocery (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

modified:   shoppingList.txt

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:   shoppingList.txt

This is the actual situation, ...

Get Git Essentials - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.