Is there a way to generate a git commit log for the last month, and export it as a CSV file? I'm looking for something I can run from the command line, or a 3rd party app. I'd like the following columns: author, date of commit, subject, file edited and hash.
3 Answers
You can use the --since
and --pretty
option of git log
, for instance:
git log --since="last month" --pretty=format:'%h,%an,%ar,%s' > log.csv
Refer to the PRETTY FORMATS section of the Git log man page for more options.
-
1Works perfectly! Thank you. Is there a way to include (in a separate column) which file was affected/edited? May 9, 2012 at 19:58
-
2This is more tricky, because in general, there is more than one file affected by a commit. Do you want one line by file (thus multiple lines for the same commit) or a (semicolon separated?) list of files affected per commit? In any case, this will involve a shell script I guess.– SimonMay 9, 2012 at 20:39
-
1This is nice. But is there also an option for the last month from the 1th to the last day of it? Apr 7, 2015 at 0:36
-
7adding quotes would improve the output csv file if the commit messages have commas. "%h","%an","%ar","%s"– dwenausMay 29, 2016 at 16:26
-
The result for me has the following format:
Commit-ID,User,x hours ago,first line of commit message
– testingJul 25, 2019 at 13:48
This command creates a formatted CSV containing hash,user,date/time,description,files changed,insertions,deletions
git log --pretty=format:'"%h","%an","%aD","%s",' --shortstat --no-merges | paste - - - > log.csv
-
3merge commits were messing up the output for me, adding the
--no-merges
parameter helped with that. I also used%x09
for a tab separator instead of comma for those commit texts containing commas. Jun 2, 2014 at 9:39
To add, if you want to apply date range, add --after or --before in this format "yyyy-mM-d"
git log --before="2016-12-1" --pretty=format:'"%h","%an","%ae","%aD","%s",' --shortstat --no-merges | paste - - - > log.csv