threads / discuss / 25295

wierd git show syntax

Subject: wierd git show syntax

## tl;dr

5 messages between Sep 30, 2010 and Oct 4, 2010.

replies: 4people: 3as markdown or json

Geoff Russell· Sep 30, 2010, 05:02 UTC · lore
Hi,
$ git show XXXX:data/path/object.c

Gives me what I want, a cat of the objects contents. However for some files I get a message about ambiguous argument telling me to separate paths from revisions with '--'. Okay so I try that:

$ git show -- XXXX:data/path/object.c
But it gives me nothing
$ git show XXXX -- data/path/object.c
Gives me a git diff output for the object.
This is all with git 1.6.2.3
What's happening here? Why aren't all these equivalent?

Cheers, Geoff Russell

Tomas Carnecky· Sep 30, 2010, 08:46 UTC · re: Geoff Russell · lore

Re: wierd git show syntax

On 9/30/10 7:02 AM, Geoff Russell wrote:
> Hi,
> 
> $ git show XXXX:data/path/object.c
Show me the contents of the file at data/path/object.c in revision XXXX.
Show 5 quoted lines
> Gives me what I want, a cat of the objects contents. However
> for some files I get a message about ambiguous argument telling me to
> separate paths from revisions with '--'. Okay so I try that:
> 
> $ git show -- XXXX:data/path/object.c

Show me the commit HEAD but limit the diff to the path XXXX:data/path/object.c.

There is an implicit HEAD before the double dash. You probably want the double dash *after* the object, to force git to parse that string as an object and not a path:

$ git show XXXX:data/path/object.c --
> But it gives me nothing
> 
> $ git show XXXX -- data/path/object.c
Show me the commit XXXX but limit the diff to the path data/path/object.c.
Show 6 quoted lines
> Gives me a git diff output for the object.
> 
> 
> This is all with git 1.6.2.3
> 
> What's happening here? Why aren't all these equivalent?
no.
tom
Tomas Carnecky· Sep 30, 2010, 09:02 UTC · re: Tomas Carnecky · lore

Re: wierd git show syntax

On 9/30/10 10:46 AM, Tomas Carnecky wrote:
>> What's happening here? Why aren't all these equivalent?
> 
> no.
A 'no' does not really fit a 'why?' question. I should explain.

Someone (Linus?) long ago decided that the revision parsing work that way. It's pretty powerful, even the smallest colon and double dash have a meaning. But it can be complicated for someone new to git to understand. See 'man gitrevisions' to understand how git parses revisions. Sadly the effect of double bash is not described in the git-show man page. But in most commands it's used to separate revisions from paths. Example: if you have a file and branch both named master, 'git log master --' will show you the log of that branch while 'git log -- master' will show you the log of HEAD but limit it to commits which touched the file master. Again, there's an implicit HEAD before the double dash.

tom
Matthieu Moy· Sep 30, 2010, 11:32 UTC · re: Geoff Russell · lore

Re: wierd git show syntax

Geoff Russell <geoffrey.russell@gmail.com> writes:
Show 7 quoted lines
> Hi,
>
> $ git show XXXX:data/path/object.c
>
> Gives me what I want, a cat of the objects contents. However
> for some files I get a message about ambiguous argument telling me to
> separate paths from revisions with '--'.
This happens if data/path/object.c doesn't exist in XXXX.

A common mistake is to write XXXX:relative/path when Git expects a path relative to the tree root. Git >= 1.7 would give you a more friendly error message in this case.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Geoff Russell· Oct 4, 2010, 22:32 UTC · re: Matthieu Moy · lore

Re: wierd git show syntax

On Thu, Sep 30, 2010 at 10:02 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 11 quoted lines
> Geoff Russell <geoffrey.russell@gmail.com> writes:
>
>> Hi,
>>
>> $ git show XXXX:data/path/object.c
>>
>> Gives me what I want, a cat of the objects contents. However
>> for some files I get a message about ambiguous argument telling me to
>> separate paths from revisions with '--'.
>
> This happens if data/path/object.c doesn't exist in XXXX.

Thanks Matthieu and Tom for your explanations on this. It's clearer now ... even if my intuition failed to match the syntax!

Cheers, Geoff

← back to recent threads