Reputation: 443
I have looked into the forum, but with no luck.
Requirement :
Run GIT LOG (format) command and write the results into an Excel File .
I have seen examples wherein with GIT Log command, data can be written into a CSV, but formatting is double the effort.
Any utility or approach would be helpful.
Thanks Milind
Upvotes: 43
Views: 49412
Reputation: 21
If anyone came here looking for PowerShell, here's how the first part of avs099's answer translates:
echo "Commit Hash,Authored Date,Author Name,Author Email,Comment Subject,Files Changed,Lines Added,Lines Deleted" > gitlogs.csv
$gitlogs = git log --since='last year' --pretty=format:'%x02%x22%h%x22%x2C%x22%ad%x22%x2C%x22%an%x22%x2C%x22%ae%x22%x2C%x22%s%x22%x2C' --date=iso-strict --shortstat
$gitlogs -Split [Environment]::NewLine -Join '' -Replace '\x02',[Environment]::NewLine >> gitlogs.csv
Key
>
== create/overwrite>>
== append to file%x02
== Start of Text%x22
== Quote mark%x2C
== CommaThe headings describe %h
, %s
etc. See the git help page for more info.
--since='last year'
could also be --since='YYYY-MM-DD'
Upvotes: 0
Reputation: 402
Simple Solution
git log --pretty=format:%h,%ad,%an,%ae,%s > gitlogs.csv
Upvotes: 5
Reputation: 4779
I found the answers here quite good. I hacked a script based mostly on waht @avs099 proposed, here it is for ease of reference:
#!/bin/bash
REPO=$1
DIR=`realpath -L ./$REPO`
echo going to compute stats for $DIR
cd $DIR
git checkout main
git pull
git log --since='last year' --date=short --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
mv res.csv git-log.csv
awk -i inplace 'BEGINFILE{print "commit,user,date,comment,files changed,insertions,deletions"}{print}' git-log.csv
sed -i '/^$/d' git-log.csv
cd -
Upvotes: 1
Reputation: 11227
my 2 cents in case anyone is looking:
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.sh
file or just copy/paste into console.
I think it's relatively self-explaining but just in case:
--all
takes logs from all branches--since
limits the number of commits we want to look at--shortstat
- to get some idea what was done in the commitUpvotes: 38
Reputation: 3752
Git gives your the control on how to format the log output using pretty
option. Check this out:
git log --pretty=format:%h,%an,%ae,%s
This prints the log in the format of (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
Upvotes: 71