From a2b7a3b3a966c5801efe968d4b5656fa5a885409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 3 Feb 2011 13:23:34 +0700 Subject: diff: support --cached on unborn branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "git diff --cached" (without revision) used to mean "git diff --cached HEAD" (i.e. the user was too lazy to type HEAD). This "correctly" failed when there was no commit yet. But was that correctness useful? This patch changes the definition of what particular command means. It is a request to show what _would_ be committed without further "git add". The internal implementation is the same "git diff --cached HEAD" when HEAD exists, but when there is no commit yet, it compares the index with an empty tree object to achieve the desired result. Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Documentation/git-diff.txt') diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index f6ac847507..49105102db 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -38,6 +38,8 @@ directories. This behavior can be forced by --no-index. commit relative to the named . Typically you would want comparison with the latest commit, so if you do not give , it defaults to HEAD. + If HEAD does not exist (e.g. unborned branches) and + is not given, it shows all staged changes. --staged is a synonym of --cached. 'git diff' [--options] [--] [...]:: -- cgit v1.2.3