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


The staging area is a tree file called index that stores information (file, directory, message, …) 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).



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

Add (Staging)

Reset (Unstaging)

git reset --hard
HEAD is now at xxxx commit


git cat-file -p master^{tree}

Git - cat-file

List the files

For the next commit (staged)

git diff-index HEAD

In the index

To list the files the contents of the index with the stage information:

  • The mode of the file
  • The stage of the file (in next commit or not)
  • and the pathname of the file
git ls-files --stage
100644 70e413f03019cd301ebb955a3cc4d1ce9cad3cba 0       .gitattributes
100644 28a0ee7ed92f8962153865cf3eebf44e14c5c70e 0       .gitignore
100644 652381035ef9a14fdfb0e138ea33f2b777f1d06e 0
100644 7796e9eaf8ba750963df16029fd043b1905cbadc 0       conf/local.php
100644 cab897e88d877554458012df4447ea35f05dfb35 0       media/android-chrome-192x192.png
100644 6a4da3d8a25a9ba97b72d609c23ccc9fa8de43c4 0       media/android-chrome-512x512.png

To add file system information (modified date, …), add the debug option.

git ls-files --debug
100644 3eb4c7064f05a84ba975d45065b51114bcffef29 0       pages/slot_header.txt
  ctime: 1681850743:763163236
  mtime: 1681850743:763163236
  dev: 2049     ino: 155378090
  uid: 1002     gid: 1001
  size: 557     flags: 0



git restore to restore a file to the last state


With rm:

  • Remove a file from staging
git rm --cached path/to/file
  • Remove all files from staging area
git rm --cached -r .


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

Discover More

is a content-addressable file system used to track directory tree content (as defined by its creator Linux Torvald) The tracking happens with...
Git - Add command (Staging) - Add a change to the next commit

Add file contents to the staging area (known also as the index). This statement will add all files and any new untracked files.
Git - Checkout

A checkout will change the current branch Specifically, it will checkout the files from the repository for a branch in the working directory to match the version in the index (staging area) ...
Git - Database

The git core database is a key store value where a key value entry is known as an object. (All data in Git are objects) The database is mostly composed: * of tree of object * * * *...
Git - Diff

in Git Diff between the head commit of the current branch (HEAD) and the current file not yet committed (in the working area) Between the head of the main branch and the head commit of the current...
Git - End Of Line

This page is talking the EOL characters management in git. In the .gitattributes file One file All files with .txt extension exclusion If you...
Git - File

File management in Git (blob and not directory) blob object on the local file system or not (ie in the git file system database) See and short status A file (or blob) identifier is the...
Git File Lifecycle
Git - File Status

The status of a file in a working directory is one of: where: untracked See unmodified modified staged means that the file is in the index (proposed next commit) Each file in a working...
Git - Git (executable|command line)

The git executable where: --git-dir is the location of the repository files --work-tree is the location of the work tree Command Description add Add file contents to the index add--interactive...
Git - Index (proposed next commit)


Share this page:
Follow us:
Task Runner