Note to mods: This is not a duplicate of Start a Git commit message with a hashmark (#). That question is specifically regarding git commit
, while this is regarding .gitconfig file syntax.
A web search will turn up many answers for how to escape a hash at the beginning of a commit message, but I'm unable to find any solution for including a hash in an alias in a .gitconfig file. This is the alias I'm trying to use:
[alias]
pr-log = !git fetch && git log --reverse --pretty=format:\"### [%s](https://github.com/my-username/commit/%H)%n%n%b\" HEAD...origin/develop
When run in the shell this produces nicely formatted markdown, but since # is a comment character in .gitconfig, it gets parsed as pr-log = log --reverse --pretty=format:\"
. I tried \#\#\#
, but that doesn't work.
CodePudding user response:
Ugh, as soon as I finished typing my question I found the answer in the git aliases doc. The solution is to quote the entire alias:
[alias]
pr-log = "!sh -c 'git fetch && git log --reverse --pretty=tformat:\"### [%s](https://github.com/my-username/commit/%H)%n%n%b\" HEAD...origin/develop'"
CodePudding user response:
Similar to your own answer, but using a shell function to get rid of a layer of quoting:
pr-log = "!f() { git fetch && git log --reverse --pretty=tformat:'### [%s](https://github.com/my-username/commit/%H)%n%n%b' HEAD...origin/develop; }; f"