Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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 is, at least when executed directly as a command in bash, 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, in your case, 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.

To be honest, 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 around to get the right combination on you system, while using PuTTY and all.

share|improve this answer
    
Do you have documentation for this? For me at least it is the other way around. –  wes Apr 21 '11 at 14:28
    
@wes: Added link to documentation. Rewrote answer. –  lesmana Apr 21 '11 at 18:04
    
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' –  meagar Jul 5 '11 at 18:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.