Moerwald
Moerwald

Reputation: 11264

.gitconfig "bad config line" due alias

I extended my .gitconfig with a daily alias that works one the command line. Command:

git log --since '2 day ago' --author='\(MYSURNAME\)\|\(mysurname\)'

Due to the fact that I'm either merging Pull Requests via Bitbucket and committing directly from the command line, I can find my name in the Git log in either lowercase or uppercase ... Therefore I'm using above "regex" at the --author switch. Anyhow the command works perfectly on the command line. If I'm the command as an alias in my global .gitconfig I get the following error:

fatal: bad config line 53 in file ...

Which points the newly added alias. My .gitconfig:

[alias]
    d = difftool
    graph = log --graph --pretty=format:'%Cgreen%h%Creset -%C(yellow) %d%Creset %s %sCgreen(%cr) %C(bold magenta)<%an>%Creset' --abbrev-commit --date=relative 
    daily = log --since '2 day ago' --author="\(MYSURNAME\)\|\(mysurname\)"

Do I've to perform a special kind of escaping when using an alias of that kind?

Thx.

Upvotes: 1

Views: 277

Answers (1)

torek
torek

Reputation: 488193

When Git reads a config file, backslashes—even if they are inside quotes—are escape-sequence-introduction characters. The second character after the backslash is the character that goes into the final alias, in this case. Hence you need two backslashes to produce one backslash in the command that gets run:

daily = log --since '2 day ago' --author="\\(MYSURNAME\\)\\|\\(mysurname\\)"

(In Unix-like shells, the rules are different than they are in .git/config files, so don't just blindly use the same rule for command line interactions.)

Upvotes: 2

Related Questions