# Re: [PATCH] git-diff: Introduce --index and deprecate --cached.

3 messages from 2006-11-30 to 2006-12-09. Participants: Junio C Hamano, Andreas Ericsson.
Thread: https://gitlist.dev/t/43407

## Andreas Ericsson, 2006-11-30 11:43

Subject: [PATCH] git-diff: Introduce --index and deprecate --cached.
Message-ID: <20061130115913.EA36C5BA19@nox.op5.se>
URL: https://gitlist.dev/e/20061130115913.EA36C5BA19%40nox.op5.se

```
'git diff --cached' still works, but its use is discouraged
in the documentation. 'git diff --index' does the same thing
and is consistent with how 'git apply --index' works.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Documentation/git-diff.txt |    6 ++++--
 builtin-diff.c             |    2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index 228c4d9..3144864 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -22,8 +22,10 @@ the number of trees given to the command.
 
 * When one <tree-ish> is given, the working tree and the named
   tree are compared, using `git-diff-index`.  The option
-  `--cached` can be given to compare the index file and
+  `--index` can be given to compare the index file and
   the named tree.
+  `--cached` is a deprecated alias for `--index`. It's use is
+  discouraged.
 
 * When two <tree-ish>s are given, these two trees are compared
   using `git-diff-tree`.
@@ -47,7 +49,7 @@ Various ways to check your working tree::
 +
 ------------
 $ git diff            <1>
-$ git diff --cached   <2>
+$ git diff --index    <2>
 $ git diff HEAD       <3>
 ------------
 +
diff --git a/builtin-diff.c b/builtin-diff.c
index a659020..1c535b1 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -137,7 +137,7 @@ static int builtin_diff_index(struct rev_info *revs,
 	int cached = 0;
 	while (1 < argc) {
 		const char *arg = argv[1];
-		if (!strcmp(arg, "--cached"))
+		if (!strcmp(arg, "--index") || !strcmp(arg, "--cached"))
 			cached = 1;
 		else
 			usage(builtin_diff_usage);
-- 
1.4.4.1.GIT

```

## Junio C Hamano, 2006-12-09 02:24

Subject: Re: [PATCH] git-diff: Introduce --index and deprecate --cached.
Message-ID: <7vac1xg61s.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vac1xg61s.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20061130115913.EA36C5BA19@nox.op5.se>

```
Andreas Ericsson <ae@op5.se> writes:

> 'git diff --cached' still works, but its use is discouraged
> in the documentation. 'git diff --index' does the same thing
> and is consistent with how 'git apply --index' works.

Although I've applied this long time ago (in git timescale
anyway), this patch and the above rationale is wrong.

'diff --cached' is more in line with how 'apply --cached' works,
not how 'apply --index' works.

With apply, --cached and --index both tell the command to be
aware of the index, but --cached means "operate on the index,
and never look at working tree", while --index means "operate
both on the index and working tree at the same time".  In
particular, the former does not care if the file in the working
tree matches the index, while the latter does.

'diff --cached' is about the tree and the index without looking
at the working tree.  Since there is no mode of operation that
looks at both the index and the working tree in the underlying
diff-index, I made the mistake of applying this patch, but it is
conceivable that we may want to have a 'diff --index' that
compares HEAD, the index and the working tree, perhaps in a
combined diff format.

I think we should revert this patch.

```

## Junio C Hamano, 2006-12-09 02:29

Subject: Re: [PATCH] git-diff: Introduce --index and deprecate --cached.
Message-ID: <7v64clg5u9.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64clg5u9.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <7vac1xg61s.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> writes:

> Although I've applied this long time ago (in git timescale
> anyway), this patch and the above rationale is wrong.
>
> 'diff --cached' is more in line with how 'apply --cached' works,
> not how 'apply --index' works.

Side note.  I do not think --index and --cached are a good pair
of words to express the different semantics (the former works on
the working tree through the index, the latter works only on the
cached data and not on the working tree).  I was only pointing
out that making 'diff --index' a synonym to 'diff --cached'
closes the door for the possibility to have these two semantics
that are consistently spelled (well, maybe "confusingly
spelled", but still consistently) between diff and apply.

```
