git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Arthur Etchells <adetchells@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Inconsistency in specifying commit & path for git diff
Date: Tue, 09 Oct 2012 14:03:37 -0700	[thread overview]
Message-ID: <7vliffe4t2.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <50747E48.3060203@gmail.com> (Arthur Etchells's message of "Tue, 09 Oct 2012 15:43:04 -0400")

Arthur Etchells <adetchells@gmail.com> writes:

> git diff <commit>..<commit>
> and
> git diff <commit> <commit>
> both succeed
> however
> git diff <commit>:<path>..<commit>:<path>
> fails while
> git diff <commit>:<path> <commit>:<path>
> succeeds
> ...
> It seems logical to support the '..' syntax in both for consistency.

"git diff A..B" is an illogical thing to say in the first place.  It
only happens to work by historical accident, and for that "it used
to work like so from the beginning, do not break backward
compatibility" reason, we have kept it working.

But you are better off unlearning it to keep your sanity when
learning git as a new user.

The dot notation is about a range.  A..B talks about the set of
commits that are ancestors of B but not ancestors of A.

    $ git log A..B

makes perfect sense to show such a range.

But "diff" is about "comparing two endpoints".  There is nothing
"range" about such a comparison.  When you compare the state at A
and at B, you do not even look at anything in between.  That is why
the canonical way to say it is

    $ git diff A B

and not

    $ git diff A..B ;# WRONG. DO NOT DO THIS.

And <commit>:<path> is a way to name an entity at <path> in the tree
recorded in the <commit>.  Typically you name a blob, not a tree
that represents a subdirectory, with this syntax.

Now, B1..B2, when B1 and B2 are blobs (or anything that is not
commit-ish), does not make sense even as a range, and such a request
is detected as an error at the syntactic level (i.e. without even
starting to "compare").

    $ git diff HEAD:Makefile..HEAD~4:Makefile ;# WRONG. DO NOT DO THIS.

If you want to compare two blobs, you can do so with the canonical
"compare two things" syntax.

    $ git diff HEAD:Makefile HEAD~4:Makefile

      parent reply	other threads:[~2012-10-09 21:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09 19:43 Inconsistency in specifying commit & path for git diff Arthur Etchells
2012-10-09 20:37 ` Andreas Schwab
2012-10-09 21:03 ` Junio C Hamano [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=7vliffe4t2.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=adetchells@gmail.com \
    --cc=git@vger.kernel.org \
    /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).