1

I noticed that in git version 1.8.3.1 (provided by CentOS 7) it seems this command is not working:

git cat-file -t -- "5378198ea7a83f5fa9bb3ba17f51be3a6ffbecc1:README.md"

(Obviously specify a correct git hash and an existing file at that revision)

This is the standard error:

usage: git cat-file (-t|-s|-e|-p|<type>|--textconv) <object>
   or: git cat-file (--batch|--batch-check) < <list_of_objects>

<type> can be one of: blob, tree, commit, tag
    -t                    show object type
    -s                    show object size
    -e                    exit with zero when there's no error
    -p                    pretty-print object's content
    --textconv            for blob objects, run textconv on object's content
    --batch               show info and content of objects fed from the standard input
    --batch-check         show info about objects fed from the standard input

To me, it seems that the problem is the "--" escape parameter that is interpreted as a type instead of an escape for consecutive arguments. In fact, this works to me:

git cat-file -t "5378198ea7a83f5fa9bb3ba17f51be3a6ffbecc1:README.md"

It exists with 0 with this result:

blob

So, in short.

Question

How do you suggest to proceed to discover when the "--" parameter was introduced in git?

Related documents:

1 Answer 1

2

git cat-file used to have a strict check on the number of arguments to it, which meant that -- couldn’t be used. The check happened before options were parsed, which is why you get the usage output immediately, with no indication of why the arguments are invalid.

This was removed in May 2015; the first release containing this change is 2.5.0.

To figure this out, I compared cat-file.c in version 1.8.3.1 to its current state; I noticed the check on argument versions, then looked for the commit which removed it.

4
  • Thank you Stephen. I'm marking this as accepted solution. I think it could be useful to mention their changelog that clarify this and seems to confirm that this was changed in 2015: github.com/git/git/blob/… thank you so much Mar 22 at 16:06
  • I thought of mentioning the changelog, but I couldn’t find anything that references this change explicitly; can you? Mar 22 at 16:09
  • I only see this part in the changelog about that: «A heuristic we use to catch mistyped paths on the command line "git <cmd> <revs> <pathspec>" [<omissis>] must always be disambiguated with "--"» github.com/git/git/blob/… Mar 23 at 8:27
  • Yes, but that doesn’t explain why cat-file suddenly started accepting --. It probably wasn’t noticed at the time, since the change was part of a code cleanup rather than an explicitly externally-visible change. Mar 23 at 8:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .