IndexCommandQuickref

From Git SCM Wiki
Jump to: navigation, search

See IndexFile to know what "index" is

Contents


Update file content to index

With development version (FIXME: add version here), you can do: git add file

Otherwise use: git update-index file

Add a file to index

git add file

Low-level command is: git update-index --add file

Delete a file from index

git rm file

Note: with new git version, the above command also removes file in working directory if it matches HEAD

Low-level command is: git update-index --remove [--force-remove] file

Read a tree to index

To read a tree from HEAD (reset index), do: git reset

To read an abitrary tree to index: git reset <commit-ish>

Low-level command is: git read-tree <tree-ish>

Read a file from a tree to index

Sorry there is currently no short command for this.

git ls-tree treeish file | git update-index --index-info --stdin

Copy a file from index to working directory

git checkout file

Or low-level version: git checkout-index file

Refresh index

git status

Actually the above command does more, but who cares :-)

Low-level command is: git update-index --refresh

Copy entire index to working directory

git checkout -f

Low-level command: git checkout-index

List files in index

git ls-files

Compare index file listing and working directory

git status

Or a lower command: git ls-files {--deleted|--others|--ignored|--stage|--unmerged|--killed|--modified} See man page for more information

View a file from index (Output a file from index to stdout)

git cat-file -p ::<file>

To see files from stage <n>, do: git cat-file -p :<n>:<file>

Diff between working directory and index

git diff

Low-level command: git diff-files

Diff between index and a tree

To diff index with a tree: git diff --cached

To diff with an abitrary tree: git diff --cached <tree-ish>

Low-level command: git diff-index --cached <tree-ish>


Personal tools