<(git log --oneline) 的读取循环与终端的 "git log --oneline" 的输出不同

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

我遇到了一个奇怪的问题。我正在尝试解析 git 命令的输出。当我从命令行 运行 git 命令时,它按预期工作:

$ 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.)

但是一旦我尝试重定向或通过管道输出,括号内的任何内容都会消失:

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

[编辑:请注意,echo 命令严格用于说明问题。实际脚本会将结果拆分成多个变量进行解析处理]

$ 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|

但是我编写的一个快速 shell 脚本回声括号工作正常:

$ 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

我被难住了。谁能帮我解决这个问题?

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

勾选 git log--decorate 选项:

--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.

看起来您在 git 配置中的某处设置了 --decorate=auto

要强制引用名称(包括标签),只需指定:

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