【问题标题】:git log --pretty=format windows strange behaviorgit log --pretty=format windows 奇怪的行为
【发布时间】:2018-10-28 17:45:03
【问题描述】:

我将问题简化为最低限度。 linux下的git命令是这样的:

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

给了我一个有效的 json 元素,比如:

{"commit":"20cafdecc9898113ac6215ae70cd7622dc2cae3b"}

在 windows 下我获得了一个无效的 json 元素,因为在某种程度上 windows 似乎删除了双引号元素并且我获得了:

{commit:20cafdecc9898113ac6215ae70cd7622dc2cae3b}

你知道为什么吗,或者我该如何解决它使其在两个操作系统下都可以工作? 谢谢!

【问题讨论】:

    标签: json git cmd git-log


    【解决方案1】:

    我假设你在 Linux 上的 shell 不是 bash shell,因为我在 Linux 上的 bash shell 给了我与 Windows 上相同的输出 - 没有双引号。

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

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

    这适用于 Linux 上的 bash 和 Windows 上的 bash。我没有在 Windows 上使用cmd 对其进行测试。

    【讨论】:

    • 谢谢你啊,你可能是对的,很抱歉我在我的问题中提供了不正确的信息。我在 windows 和 linux 上运行的命令是带有单引号 git log --pretty='format:{"commit":"%H"}' 的命令,但在 windows 中使用 'cmd' 启动的命令提示符中,我仍然获得不带双引号的日志...我可以在 windows 下添加它git-bash 中的“正确”输出(带双引号)。
    • 我不知道cmd的引用规则,抱歉。
    • 没问题啊,谢谢!每个双引号转义的命令似乎都有效,但现在我遇到了另一个问题,我问了here
    猜你喜欢
    • 1970-01-01
    • 2016-06-06
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    相关资源
    最近更新 更多