leeyuiwah
leeyuiwah

Reputation: 7152

git command alias in gitconfig: what characters to escape

This git command works well in git bash

$ git log --author="\(david\)\|\(peter\)" --format="%h %<(22)%an %s"

But when I put it into my gitconfig:

$ grep -E -e "alias|lolaf" .gitconfig
[alias]
        lolaf   = log --author="(david)|(peter)" --format="%h %<(22)%an %s"
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --pretty=format:'%h %\\<(22)%an %s'
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --format="%h %\\<(22)%an %s"
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --format="%h %<(22)%an %s"
        # lolaf = log --author="\(david\)\|\(peter\)" --format="%h %<(22)%an %s"
        # lolaf = log --author="(david)|(peter)" --pretty-format="%h %<(22)%an %s"

I got this error

$ git lolaf -- .
fatal: bad revision '%<(22)%an'

I believe the problem is due to the wrong escaping of special characters. As you can see I tried a few different variants but they also did not work.

Any suggestion?

Upvotes: 4

Views: 907

Answers (1)

leeyuiwah
leeyuiwah

Reputation: 7152

(I am providing my own answer here. Just in this case this may help someone.)

After many more trials, I finally find the right combination.

  1. Use single quote to escape <
  2. Use single quote and double backslash \\ to replace the single backslash used in git bash

So,

lolaf   = log --author='\\(david\\)\\|\\(peter\\)' --format='%h %<(22)%an %s'

Below the first one worked, the other were results of my experimentation:

$ grep -E -e "alias|lolaf|worked" .gitconfig
[alias]
        lolaf   = log --author='\\(david\\)\\|\\(peter\\)' --format='%h %<(22)%an %s'
        # this worked
        # lolaf = log --author='\\(david\\)\\|\\(peter\\)'
        # lolaf = log --author='\\(david\\)|\\(peter\\)'
        # lolaf = log --author="\\(david\\)|\\(peter\\)"
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)"
        # lolaf = log --author="david\\|peter" --format='%h %<(22)%an %s'
        # lolaf = log --author="\\(david\\)" --format='%h %<(22)%an %s'
        # this worked
        # lolaf = log --format='%h %<(22)%an %s'
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --format='%h %<(22)%an %s'
        # lolaf = log --author="\(david\)\|\(peter\)" --format='%h %<(22)%an %s'
        # lolaf = log --author='(david)|(peter)' --format='%h %<(22)%an %s'
        # lolaf = log --author="(david)|(peter)" --format='%h %<(22)%an %s'
        # lolaf = log --author="(david)|(peter)" --format="%h %<(22)%an %s"
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --pretty=format:'%h %\\<(22)%an %s'
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --format="%h %\\<(22)%an %s"
        # lolaf = log --author="\\(david\\)\\|\\(peter\\)" --format="%h %<(22)%an %s"
        # lolaf = log --author="\(david\)\|\(peter\)" --format="%h %<(22)%an %s"
        # lolaf = log --author="(david)|(peter)" --pretty-format="%h %<(22)%an %s"

Upvotes: 4

Related Questions