git log--漂亮=格式化windows的奇怪行为



我将问题简化为最低项。在linux下,git命令如下:

git log --pretty=format:{"commit":"%H"}

给了我一个有效的json元素,所以类似于:

{"commit":"20cafdecc9898113ac6215ae70cd7622dc2cae3b"}

在windows下,我获得了一个无效的json元素,因为在某些方面,windows似乎删除了双引号元素,我获得:

{commit:20cafdecc9898113ac6215ae70cd7622dc2cae3b}

你知道为什么吗?或者我该如何修复它,使其在两个操作系统下都能工作?非常感谢。

我认为Linux上的shell不是bashshell,因为我在Linux上的bashshell给我的输出与在Windows上相同——没有双引号。

双引号是大多数shell的特殊字符,因此您必须通过"转义"或"引用"来保护它们。

git log --pretty=format:{"commit":"%H"}
git log --pretty='format:{"commit":"%H"}'

这适用于Linux和Windows上的bash。我还没有在Windows上用cmd测试过它。

最新更新