将 GIT LOG 导出为 Excel 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39253307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:13:39  来源:igfitidea点击:

Export GIT LOG into an Excel file

gitlogging

提问by milindbangar

I have looked into the forum, but with no luck.

我查看了论坛,但没有运气。

Requirement :

要求 :

Run GIT LOG (format) command and write the results into an Excel File .

运行 GIT LOG (format) 命令并将结果写入 Excel 文件。

I have seen examples wherein with GIT Log command, data can be written into a CSV, but formatting is double the effort.

我见过一些例子,其中使用 GIT Log 命令,数据可以写入 CSV,但格式化是双倍的努力。

Any utility or approach would be helpful.

任何实用程序或方法都会有所帮助。

Thanks Milind

谢谢米林德

回答by joker

Git gives your the control on how to format the log output using prettyoption. Check this out:

Git 让您可以使用pretty选项控制如何格式化日志输出。看一下这个:

git log --pretty=format:%h,%an,%ae,%s

This prints the log in the format of (hash [abbreviated], author name, author email, subject).

这会以 (hash [abbreviated], author name, author email, subject) 的格式打印日志。

To see the full list of format options:

要查看格式选项的完整列表:

git help log

And scroll down until you see the list of format options.

然后向下滚动,直到看到格式选项列表。

To redirect the output, use >redirection operator as follows:

要重定向输出,请使用>重定向运算符,如下所示:

git log --pretty=format:%h,%an,%ae,%s > /path/to/file.csv

回答by avs099

my 2 cents in case anyone is looking:

我的 2 美分,以防有人在看:

echo "commit id,author,date,comment,changed files,lines added,lines deleted" > res.csv 
git log --since='last year'  --date=local --all --pretty="%x40%h%x2C%an%x2C%ad%x2C%x22%s%x22%x2C" --shortstat | tr "\n" " " | tr "@" "\n" >> res.csv
sed -i 's/ files changed//g' res.csv
sed -i 's/ file changed//g' res.csv
sed -i 's/ insertions(+)//g' res.csv
sed -i 's/ insertion(+)//g' res.csv
sed -i 's/ deletions(-)//g' res.csv
sed -i 's/ deletion(-)//g' res.csv

and either save it into git-logs-into-csv.shfile or just copy/paste into console.

并将其保存到git-logs-into-csv.sh文件中,或者只是复制/粘贴到控制台中。

I think it's relatively self-explaining but just in case:

我认为这是相对不言自明的,但以防万一:

  • --alltakes logs from all branches
  • --sincelimits the number of commits we want to look at
  • --shortstat- to get some idea what was done in the commit
  • --all从所有分支获取日志
  • --since限制我们想要查看的提交数量
  • --shortstat- 了解提交中做了什么