git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] diff: support --cached on unborn branches

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 31, 2010, 03:24 UTC
Message-ID
<20101031032413.GA27346@do>
In-Reply-To
<7vwroz3vj8.fsf@alter.siamese.dyndns.org>
On Sat, Oct 30, 2010 at 08:12:27PM -0700, Junio C Hamano wrote:
Show 24 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> 
> > "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 still 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: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> 
> Will take a look at it, and queue.  Thanks.
> 
> >  "git diff --cached HEAD" does fail, but I don't really care.
> 
> I _do_ care, and so should you.  And I think it _should_ fail, if the user
> explicitly asked to compare the index with HEAD that does not exist yet.
> 
> As we are updating the semantics of a Porcelain command, there should be
> an update that explains the new usage in the documentation, no?
Yes.
--8<--
diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index dd1fb32..518e46b 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -32,7 +32,9 @@ directories. This behavior can be forced by --no-index.
 	This form is to view the changes you staged for the next
 	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.
+	do not give <commit>, it defaults to HEAD. If HEAD does
+	not exist (e.g. unborn branches) and <commit> is not
+	given, it shows all staged changes.
 	--staged is a synonym of --cached.
 
 'git diff' [--options] <commit> [--] [<path>...]::
--8<--
-- 
Duy
Previous: Junio C HamanoNext: Nguyễn Thái Ngọc Duy
Message 7 of 9 in “diff: support --root --cached combination”
  1. diff: support --root --cached combinationNguyễn Thái Ngọc Duy, Oct 29, 2010
  2. Jonathan NiederOct 29, 2010
  3. Nguyen Thai Ngoc DuyOct 29, 2010
  4. Junio C HamanoOct 29, 2010
  5. diff: support --cached on unborn branchesNguyễn Thái Ngọc Duy, Oct 30, 2010
  6. Junio C HamanoOct 31, 2010
  7. Nguyen Thai Ngoc DuyOct 31, 2010
  8. diff: support --cached on unborn branchesNguyễn Thái Ngọc Duy, Feb 3, 2011
  9. Jeff KingOct 29, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.