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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.