From: Yubin Ruan <ablacktshirt@gmail.com>
To: Olaf Klischat <olaf.klischat@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git diff <commit> doesn't quite work as documented?
Date: Sat, 9 Sep 2017 19:39:02 +0800 [thread overview]
Message-ID: <CAJYFCiMV62HXD8++9ThvWWV8VELG89hUf++90TTCrD8ARMk2JA@mail.gmail.com> (raw)
In-Reply-To: <0696f94d-28c2-1f4b-03ee-16553d97f318@gmail.com>
2017-09-08 0:31 GMT+08:00 Olaf Klischat <olaf.klischat@gmail.com>:
> oklischat@oklischat:/tmp$ mkdir gittest
> oklischat@oklischat:/tmp$ cd gittest/
> oklischat@oklischat:/tmp/gittest$ git init
> Initialized empty Git repository in /private/tmp/gittest/.git/
> oklischat@oklischat:/tmp/gittest$ echo foo > foo.txt
> oklischat@oklischat:/tmp/gittest$ git add foo.txt
> oklischat@oklischat:/tmp/gittest$ git commit -m foo
> [master (root-commit) 54d55f2] foo
> 1 file changed, 1 insertion(+)
> create mode 100644 foo.txt
> oklischat@oklischat:/tmp/gittest$ echo bar > bar.txt
> oklischat@oklischat:/tmp/gittest$ git add bar.txt
> oklischat@oklischat:/tmp/gittest$ git commit -m bar
> [master 83b2e74] bar
> 1 file changed, 1 insertion(+)
> create mode 100644 bar.txt
> oklischat@oklischat:/tmp/gittest$ git tag bar-added
> oklischat@oklischat:/tmp/gittest$ git rm bar.txt
> rm 'bar.txt'
> oklischat@oklischat:/tmp/gittest$ git commit -m 'rm bar'
> [master 3ca4ff9] rm bar
> 1 file changed, 1 deletion(-)
> delete mode 100644 bar.txt
> oklischat@oklischat:/tmp/gittest$
> oklischat@oklischat:/tmp/gittest$ git checkout bar-added -- bar.txt
> oklischat@oklischat:/tmp/gittest$ git reset HEAD
> oklischat@oklischat:/tmp/gittest$ git status
> On branch master
> Untracked files:
> (use "git add <file>..." to include in what will be committed)
>
> bar.txt
>
> nothing added to commit but untracked files present (use "git add" to track)
> oklischat@oklischat:/tmp/gittest$ git diff bar-added # would expect this to show no differences
> diff --git a/bar.txt b/bar.txt
> deleted file mode 100644
> index 5716ca5..0000000
> --- a/bar.txt
> +++ /dev/null
> @@ -1 +0,0 @@
> -bar
> oklischat@oklischat:/tmp/gittest$
> oklischat@oklischat:/tmp/gittest$ git diff bar-added -- bar.txt # dito
> diff --git a/bar.txt b/bar.txt
> deleted file mode 100644
> index 5716ca5..0000000
> --- a/bar.txt
> +++ /dev/null
> @@ -1 +0,0 @@
> -bar
Michael J Gruber is correct about the working-dir/working-tree things.
A quick example: add a new file with
$ echo bzz > bzz.txt
then do "git diff bar-added".
The result is the same, because "bzz.txt" is not in the working-tree.
Yubin
> oklischat@oklischat:/tmp/gittest$
>
>
> `git diff --help' says:
>
> git diff [--options] <commit> [--] [<path>...]
> This form is to view the changes you have in your working tree relative to the named <commit>.
>
> If that were entirely true, the last two commands shouldn't have shown
> any differences, right?
>
> On closer inspection, it seems that what `git diff <commit>' really
> does is take only those paths in the working directory that are also
> in <commit> and compare the resulting tree against <commit>.
>
> We should add some option to that git diff form to make it really do
> what the docs claim it does.
>
> Or am I missing something?
prev parent reply other threads:[~2017-09-09 11:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-07 16:31 git diff <commit> doesn't quite work as documented? Olaf Klischat
2017-09-08 1:26 ` Junio C Hamano
2017-09-08 12:58 ` Michael J Gruber
2017-09-09 11:39 ` Yubin Ruan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJYFCiMV62HXD8++9ThvWWV8VELG89hUf++90TTCrD8ARMk2JA@mail.gmail.com \
--to=ablacktshirt@gmail.com \
--cc=git@vger.kernel.org \
--cc=olaf.klischat@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).