1

.gitconfig在 Windows 上的文件中添加了一行:

[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.

据我了解,问题出在“|” 象征。它被命令行解释为路径。我应该以某种方式隔离它,还是其他什么?

4

2 回答 2

1

您需要转义您的报价:

[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
于 2016-01-09T21:31:50.273 回答
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'
于 2016-01-09T21:44:46.850 回答