简体   繁体   中英

git log --pretty=format windows strange behavior

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM