I was toying with a syntax to refer a commit by its commit message and then I got this error:
$ git show :/A
fatal: ambiguous argument ':/A': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
The error message is pretty clear about how to solve it, but I haven't found any documentation explaining how does git interpret a colon followed by a path. Only if followed by a branch name.
Can you please give me some references to learn more about this?
It's actually a bit trickier than you might expect, as :/A
could be three things.
There are multiple different bits of Git documentation that talk about this, but there are two main places to look:
:
-prefixes work when something is a revision specifier . :
-prefixes work when something is a pathspec . When it's just a file name, :/A
just means the file named :/A
.
As a pathspec , :/A
uses the "magic signature" character /
, no terminating :
, and the name A
, so it refers to the file named A
in the root directory (of the repository or work-tree), rather than the file :/A
in the current directory.
As a revision specifier , :/A
searches commit messages, and A
becomes a regular expression (although in this case it's a trivial regex that just matches the letter A
):
... This name returns the youngest matching commit which is reachable from any ref, including HEAD.
Using the --
you'll force Git to treat it as a pathspec , where you may want to add :(literal)
in front to protect it from interpretation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.