git log --pretty = format Windows奇怪的行为 [英] git log --pretty=format windows strange behavior

查看:553
本文介绍了git log --pretty = format Windows奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将问题降低到最低限度. 在linux下,像这样的git命令:

I reduce the problem to its lowest terms. Under linux a git command like this:

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

为我提供了一个有效的json元素,例如:

gives me a valid json element, so something like:

{"commit":"20cafdecc9898113ac6215ae70cd7622dc2cae3b"}

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

under windows I obtain a not-valid json element, because in some way windows seems to remove the double-quotes elements and I obtain:

{commit:20cafdecc9898113ac6215ae70cd7622dc2cae3b}

您知道为什么吗,或者如何解决使其在两个操作系统下都能正常工作? 谢谢!

Do you know why, or how can I fix it making it work under both os? Thank you!

推荐答案

我假设您在Linux上的shell不是bash shell,因为我在Linux上的bash shell给我的输出与Windows上的输出相同-不会重复-报价.

I assume that your shell on Linux is NOT a bash shell because my bash shell on Linux gives me the same output as on Windows - without double-quotes.

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

The doubles-quotes are special characters for most shells - so you have to protect them either by "escaping" or by "quoting".

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

这适用于Linux上的bash和Windows上的bash.我尚未在Windows上使用cmd对其进行过测试.

This works for bash on Linux and bash on Windows. I have not tested it with cmd on Windows.

这篇关于git log --pretty = format Windows奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆