String exclusion is not performed by Git; git log
has nothing to help you with this. To achieve what you need, you will need something like sed
to do line editing.
Try this (should work in most shells, but I only checked in Cygwin bash):
function escape_chars { sed -r 's/(\{\}")/\\\1/g' } function format { sha=$(git log -n1 --pretty=format:%h $1 | escape_chars) message=$(git log -n1 --pretty=format:%B $1 | escape_chars) author=$(git log -n1 --pretty=format:'%aN <%aE>' $1 | escape_chars) commit=$(git log -n1 --pretty=format:%cE $1 | escape_chars) date=$(git log -n1 --pretty=format:%cD $1 | escape_chars) echo "{\"sha\":\"$sha\",\"message\":\"$message\",\"author\":\"$author\",\"commit\":\"$commit\",\"date\":\"$date\"}" } for hash in $(git rev-list) do format $hash done
The above will exit from {
and }
, not \
, although from JSON.org both \{
and \}
are invalid screens; only \
and "
should be escaped. (Replace sed
expression with sed -r 's/("\\)/\\\1/g'
for true JSON output.)
I also left the value "commit" as in your example, although the %cE
does indeed give the commiter email address; I'm not sure what you intended.
(Now this includes the correct but rejected macrobug change . Thanks!)
source share