15

I'm trying to use Git Immersion's log alias:

[alias]
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

but Git responds with

fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

using v1.6.1. All I've done so far is two commits on master then one on a branch. This alias works for me elsewhere, what could be the problem on this particular machine?

Edit - Based on lesmana's suggestion below, I was able to determine that somehow the backslashes on the quotes had been stripped after pasting the line in PuTTY. I get the above error when using " instead of \".

1 Answer 1

20

Here is the source of the error message:

$ git log %ad
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

You will get the same error message from the following two commands:

$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
$ git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

The problem is that git log receives the following two arguments: --pretty=format:%h (or --pretty=format:\"%h) and %ad. The rest, at least when executed directly as a command in bash, is a pipe to the command %s%d, which usually does not exists. The full error message on my system thus looks like this:

$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
bash: %s%d: command not found
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

All this demonstrates that the quoting somehow got lost and %ad is interpreted as a parameter for git log. To prevent that you have to find the correct combination of quoting and escaping so that the format string is quoted correctly at time of execution.

The git config manual about alias and quoting:

Arguments are split by spaces, the usual shell quoting and escaping is supported. quote pair and a backslash can be used to quote them.

From this line I was not able to figure out how quoting and escaping works. I tried some combination of quoting and escaping in the alias but was not able to make any sense out of it.

The following lines you posted in your question works fine on my system:

[alias]
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

You will have to experiment to get the right combination on you system while using PuTTY and all.

3
  • 1
    Do you have documentation for this? For me at least it is the other way around.
    – wes
    Apr 21, 2011 at 14:28
  • @wes: Added link to documentation. Rewrote answer.
    – Lesmana
    Apr 21, 2011 at 18:04
  • 6
    I had to replace double quotes with single quotes to make the following work with git 1.7.5.1 under OSX: [alias] lg = log --graph --pretty='format:%C(yellow)%h %Creset%s%Cred%d'
    – user229044
    Jul 5, 2011 at 18:03

You must log in to answer this question.

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