1

Inspired by this reply about hex color-code in git log format, I tried to do the same. While directly using that in terminal, it is working fine:

$git log --format="%h%C(#ff69b4)%d%C(reset) %s"|head -1
dc814e3 (HEAD -> master, origin/master, origin/HEAD) Compilation help added

Problem arises if I add log --format="%h%C(#ff69b4)%d%C(reset) %s" part in alias in .gitconfig:

[alias]
  ll =log --format="%h%C(#ff69b4)%d%C(reset) %s"

which gives error:

$git ll
fatal: ambiguous argument '%s': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

A search gives a solution to the same type of problem here: suggesting a trial of escaping the " with \".

If I do this, e.g.

[alias]
  ll =log --format=\"%h%C(#ff69b4)%d%C(reset) %s\"

I get error:

git ll
fatal: Bad alias.ll string: unclosed quote

I am using:

$echo $TERM; echo $SHELL; git --version
xterm-256color
/bin/bash
git version 2.4.3

what I am doing wrong here?

Community
  • 1
  • 1
BaRud
  • 2,609
  • 2
  • 31
  • 70

3 Answers3

2

To complete Roman's answer, the problem actually lies in the fact that the alias needs to be properly enclosed in quotes :

What we have :

ll =log --format=\"%h%C(#ff69b4)%d%C(reset) %s\"

What we need :

ll ="log --format=\"%h%C(#ff69b4)%d%C(reset) %s\""
    ^                                            ^

As simple as that !

Community
  • 1
  • 1
Nadge25
  • 248
  • 2
  • 6
1

Avoid editing .gitconfig by hand, just use

git config --global alias.ll 'log --format="%h%C(#ff69b4)%d%C(reset) %s"'
Roman
  • 5,586
  • 1
  • 17
  • 37
  • Do note that if you break into the shell with `!`, then that may need to be escaped as your shell may interpret that as a substitution request for the previous command's parameter, as do any other special chars such as `$` or additional quotes used. – ken Jun 06 '19 at 22:37
0

The same happened to me.

This works fine in terminal:

git log --format="%h%C(#ff69b4)%d%C(reset) %s"

but not in .gitconfig

In .gitconfig file, I put this simple quotes, and works fine to me:

git log --format='"%h%C(#ff69b4)%d%C(reset) %s"'

In my opinion, this behavior will change based on your system. You will have to experiment to get the right combination on your system.

Lins
  • 13
  • 4