我在Windows上的.gitconfig
文件中添加了一行:
[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
如果我从git命令行(如git log --pretty=...
)使用它,此代码可以正常工作。但是当我使用别名时,我收到了这个错误:
$git hist
fatal: |: no such path in the working tree.
Use 'git <command> -- <path>...' to specify paths that do not exist locally.
据我了解,问题出在&#34; |&#34;符号。它由命令行解释为路径。我应该以某种方式或其他方式隔离它吗?
答案 0 :(得分:1)
你需要逃避你的报价:
i+1
答案 1 :(得分:1)
以下是如何设置别名以便它可以工作:(应该在单行上)
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'
# 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'