kekyc
kekyc

Reputation: 327

Error after adding an alias in global .gitconfig

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?

Upvotes: 1

Views: 137

Answers (2)

CodeWizard
CodeWizard

Reputation: 141956

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'

Upvotes: 1

Mureinik
Mureinik

Reputation: 311073

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

Upvotes: 1

Related Questions