1

I've added a line in my .gitconfig file on Windows:

[alias]
hist = log --pretty=format:"%C(yellow)%h [%ad]%C(reset) | %s%d %C(green)(%cr)%C(reset) by %C(blue)%an%C(reset)" --graph --all --decorate --date=short

This code works fine if I use it from the git command line (like git log --pretty=...). But when I use alias, I get this error:

$git hist
fatal: |: no such path in the working tree.
Use 'git <command> -- <path>...' to specify paths that do not exist locally.

As I understand, the problem is in the "|" symbol. It is interpreted by command line as a path. Should I isolate it somehow, or something else?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
kekyc
  • 317
  • 6
  • 15

2 Answers2

1

You need to escape your quotes:

[alias]
hist = log --pretty=format:\"%C(yellow)%h [%ad]%C(reset) | %s%d %C(green)(%cr)%C(reset) by %C(blue)%an%C(reset)\" --graph --all --decorate --date=short
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Here is how to set the alias so it will work: (should be on single line)

git config --global alias.hist 'log --pretty=format:"%C(yellow)%h [%ad]%C(reset) | %s%d %C(green)(%cr)%C(reset) by %C(blue)%an%C(reset)" --graph --all --decorate --date=short'

Break down and explain each part:

# set the alias at global level (name: hist)
git config --global alias.hist 

# start (and end) the alias content with the '
'log --pretty=format:"..." --graph --all --decorate --date=short'
CodeWizard
  • 128,036
  • 21
  • 144
  • 167