在我的~/.gitconfig
, 我有类似的东西
[alias]
ac = !git add --all && git commit -m
mileung = !git add --all && git commit --author="MyUserName <[email protected]>" -m
运行git ac "message"
有效,但运行git mileung "another message"
收益git add --all && git commit --author=MyUserName <[email protected]> -m: [email protected]: No such file or directory
Git 在读取配置文件行时,使用双引号来引用文本,以避免对字符进行特殊解释。结果是,在解析你的别名之后,你会读到:
!git add --all && git commit --author=MyUserName <[email protected]> -m
这是一个稍微奇怪的间距和轻微的重新排列:
!git add --all && git commit --author=MyUserName < [email protected] > -m
它告诉 shell 将git commit
命令的输入从文件定向[email protected]
并将其输出写入文件-m
。
您可以在此处转义引号,也可以使用不同类型的引号,如评论中建议的 bimlas:
mileung = !git add --all && git commit --author=\"MyUserName <[email protected]>\" -m
(这个版本让 Git 不吃双引号,所以 shell 看到它们并且shell吃掉它们,同时还保护尖括号和空格),或者:
mileung = !git add --all && git commit --author='MyUserName <[email protected]>' -m
(这里Git不吃单引号,所以shell看到单引号,用它们来引用尖括号和空格,然后吃单引号)。
(这个问题根本不是 Git 独有的;参见,例如,在 shell 脚本中转义引号的问题。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句