git log --pretty=format windows strange behavior

。_饼干妹妹 提交于 2019-12-23 06:02:18

问题


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

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

gives me a valid json element, so something like:

{"commit":"20cafdecc9898113ac6215ae70cd7622dc2cae3b"}

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!


回答1:


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.

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"}'

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



来源:https://stackoverflow.com/questions/53034425/git-log-pretty-format-windows-strange-behavior

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!