我想輸出JSON格式的文件夾的GitHub歷史記錄,其中包含作者,日期,評論和受影響的文件(路徑)文件。我可以得到所有做,但用下面的命令文件:作爲包含日期,名稱評論和文件JSON的GitHub歷史記錄
git log --pretty=format:'{%n "commit": "%H" %n "author": "%aN <%aE>",%n "date": "%ad", %n "message": "%f" %n },' [email protected] | perl -pe 'BEGIN{print "["}; END{print "]\n"}' | perl -pe 's/},]/}]/' >log.json
要獲得--name-只能與日誌命令使用的文件名,但我真的不能得到它的JSON作爲數組或「文件」。這裏是我現在所在:
git log --name-only --pretty=format:'{%n "commit": "%H" %n "author": "%aN <%aE>",%n "date": "%ad", %n "message": "%f" %n },' [email protected] | perl -pe 'BEGIN{print "["}; END{print "]\n"}' | perl -pe 's/},]/}]/' >log.json
這將產生:
{
"commit": "GUID"
"author": "My name <[email protected]",
"date": "Mon May 29 15:42:58 2017 +0300",
"message": "commit comment"
},
/folder/subfolder/file.extention
/folder/file.extention
雖然我想在指定爲JSON數組文件的提交:
{
"commit": "GUID"
"author": "My name <[email protected]",
"date": "Mon May 29 15:42:58 2017 +0300",
"message": "commit comment"
"files": [
"/folder/subfolder/file.extention"
"/folder/file.extention" ]
},
退房[這](https://stackoverflow.com/questions/38106607/git-log-json-with-changed-files)問題和[gist](https://gist.github.com/dmegorov/b64dcea2eed31e02c916fc6ed9111f4f)我修改了回答 –
謝謝@DmitryEgorov。出於某種原因,它不起作用,除了文件以外的所有內容都在執行時顯示。我注意到你使用%f,我在v3中沒有發現漂亮格式的規格。 – checho
那麼,我們可以在聊天會話中進行調試,但您可能更願意嘗試我在答案中提出的方法。 –