diff: support --cached on unborn branches
"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 <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
2e9c8789b7
commit
a2b7a3b3a9
@ -38,6 +38,8 @@ directories. This behavior can be forced by --no-index.
|
||||
commit relative to the named <commit>. Typically you
|
||||
would want comparison with the latest commit, so if you
|
||||
do not give <commit>, it defaults to HEAD.
|
||||
If HEAD does not exist (e.g. unborned branches) and
|
||||
<commit> is not given, it shows all staged changes.
|
||||
--staged is a synonym of --cached.
|
||||
|
||||
'git diff' [--options] <commit> [--] [<path>...]::
|
||||
|
||||
Reference in New Issue
Block a user