简体   繁体   中英

Is it possible to use a hash (#) in a .gitconfig?

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.

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'"

类似于您自己的答案,但使用 shell 函数来摆脱一层引用:

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM