From c3b62e0d9d7d8fb16a24dbc6dddc1ad59999b5d9 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 28 Jul 2015 17:39:55 +0300 Subject: [PATCH] Describe staging area --- pep-git.txt | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pep-git.txt b/pep-git.txt index 9dd4b0c..552901e 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -637,8 +637,31 @@ Advanced topics Staging area ------------ -Staging area aka index is a distinguishing feature of git. See -`WhatIsTheIndex +Staging area aka index aka cache is a distinguishing feature of git. +Staging area is where git collects patches before committing them. +Separation between collecting patches and commit phases provides a +very useful feature of git: one can review collected patches before +commit and even edit them - remove some hunks, add new hunks and +review again. + +To add files to the index use ``git add``. Collecting patches before +committing means you need to do that for every change, not only to add +new (untracked) files. To simplify committing in case you just want to +commit everything without reviewing run ``git commit --all`` (or just +``-a``) - the command adds every changed tracked file to the index and +then commit. + +To add hunks of patches to the index use ``git add --patch`` (or just +``-p``). To remove collected files from the index use ``git reset HEAD +-- $FILE...`` To add/inspect/remove collected hunks use ``git add +--interactive`` (``-i``). + +To see the diff between the index and the last commit (i.e., collected +patches) use ``git diff --cached``. To see the diff between the +working tree and the index (i.e., uncollected patches) use just ``git +diff``. + +See `WhatIsTheIndex `_ and `IndexCommandQuickref `_ in Git -- 2.39.2