Search code examples
gitbashcygwinparentheses

read loop from <(git log --oneline) has different output from "git log --oneline" at terminal


I'm encountering a weird problem. I'm trying to parse the output of a git command. When I run the git command from the command line, it works as expected:

$ git log --oneline 32004f
32004f9 (tag: This_is_a_tag,_too, tag: Tag_from_command_line, origin/Project_A, Project_A) Merged
65f6f61 More changes
925f619 (tag: This_is_a_tag) Pulled from remote
(etc.)

But as soon as I try to redirect or pipe the output, anything inside parentheses disappears:

$ while read -r ; do echo $REPLY; done < <(git log --oneline 32004f)
32004f9 Merged
65f6f61 More changes
925f619 Pulled from remote

[Edit: Note that the echo command is used strictly to illustrate the problem. The actual script will split the results into multiple variables for parsing and processing]

$ git log --oneline 32004f | hexdump -C | head
00000000  33 32 30 30 34 66 39 20  4d 65 72 67 65 64 0a 36  |32004f9 Merged.6|
00000010  35 66 36 66 36 31 20 4d  6f 72 65 20 63 68 61 6e  |5f6f61 More chan|
00000020  67 65 73 0a 39 32 35 66  36 31 39 20 50 75 6c 6c  |ges.925f619 Pull|
00000030  65 64 20 66 72 6f 6d 20  72 65 6d 6f 74 65 0a 64  |ed from remote.d|

But a quick shell script that I whipped up echoes parentheses works fine:

$ cat test.sh
#!/bin/bash
echo "32004f9  (HEAD -> Project_A, tag: This_is_a_tag,_too, tag: Tag_from_command_line, origin /Project_A) Merged"

$ while read -r ; do echo $REPLY; done < <(./test.sh)
32004f9 (HEAD -> Project_A, tag: This_is_a_tag,_too, tag: Tag_from_command_line, origin /Project_A) Merged

I'm stumped. Can anyone help me with this?

Bash version: GNU bash, version 4.4.12(3)-release (i686-pc-cygwin) git version: git version 2.15.0


Solution

  • Check the --decorate option for git log:

    --no-decorate, --decorate[=short|full|auto|no]

    Print out the ref names of any commits that are shown. If short is specified, the ref name prefixes refs/heads/, refs/tags/ and refs/remotes/ will not be printed. If full is specified, the full ref name (including prefix) will be printed. If auto is specified, then if the output is going to a terminal, the ref names are shown as if short were given, otherwise no ref names are shown. The default option is short.

    Looks like you have --decorate=auto set somewhere in your git config.

    To force ref names (including tags), simply specify:

    git log --oneline 32004f --decorate=short