如何为 git 命令提供不同的值并将每个值的输出存储在多个文件中?

How to give different values to a git command and store the output in several files for each value?

我正在尝试为我在 GitHub 上获得的每个差异提交生成一个 JSON 文件。 为此,我将 "SHA" 号码存储在这样的变量中:

$var=$(git log --pretty=format:'%h')

然后我想做一个 for 循环,我说对于存储在 var 中的每个值执行命令 git show 并将输出存储在一个文件中(例如 commit1.json ... . Commit100.json 等..) ( git show $var > Commits.json)

我是 shell 的新手,所以我不知道如何做到这一点。 伙计们,我真的很期待你们的帮助。

如何在生成文件时去掉特殊字符:revision_2017-03-20T140150+0100

因为稍后我试图打开它们并通过它们进行解析,但由于特殊字符我无法打开它们。

提前感谢您的帮助

git log --pretty=format:'%h' | while read revision; do git show $revision > revision_"$revision".json; done

如果您想使用其他名称(如作者日期)来命名文件,您可以这样做:

git log --pretty=format:'%h' | while read revision do date=$( git show --summary --pretty=%aI $revision | head -n 1) git show $revision > revision_"$date".json done