Git log alias - fatal: ambiguous argument '%ad': unknown revision or path

11,263

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.

Share:
11,263

Related videos on Youtube

wes
Author by

wes

Updated on September 18, 2022

Comments

  • wes
    wes over 1 year

    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 \".

  • wes
    wes about 13 years
    Do you have documentation for this? For me at least it is the other way around.
  • Lesmana
    Lesmana about 13 years
    @wes: Added link to documentation. Rewrote answer.
  • user229044
    user229044 almost 13 years
    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'