Git - Staging area (or index) - Proposed next commit

About

The staging area is a file called index that stores information about the next commit.

The index is like a pre-commit.

The “index” holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit.

Thus after making any changes to the working directory, and before running the commit command, you must use the add command to add any new or modified files to the index (ie staging area).

Command

Location

  • By default, the .git/index file
  • or the GIT_INDEX_FILE environment variable

Add (Staging)

  • Git - Add command (Staging) - Add a change to the next commit

Reset (Unstaging)

  • Git - Reset (Unstaging) - Delete a change for the next commit: as it was before
# reset as the head from the root
git reset HEAD -- .

Commit

Remove

  • Git - rm (Remove): Remove a file from staging
git rm --cached -r .

where:

  • --cached remove the paths from staging and the index without removing the files themselves
  • -r operates on directories recursively.

Powered by ComboStrap