我在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.
据我所知,问题出在"|"符号上。命令行将其解释为路径。我应该以某种方式隔离它,还是其他什么?
您需要转义您的引号:
[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 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'