简体   繁体   中英

Export git log in excel or CSV file saving original comments formatting

Good morning, I need to export the git log into a CSV or Excel file, including the comments of the commits.

I found this post that gave me some ideas: Export GIT LOG into an Excel file

However I have two additional requirement for which I haven't found help so far.

  1. I want to preserve the original text format of the comments, including new lines
  2. I want to escape the CSV delimiter, in case it is contained in the comments.

Of course, if I can fulfill the point 2), I am open to use any delimiter character. Could somebody please give an example of git log bash command?

After some test I could find the solution. I have used a git bash script.

echo "hash;user;date;comment" > gitlog.csv
git log origin/master --date=local --pretty="%h%x3B%an%x3B%ad%x3BCOMMENTMARK%BCOMMENTMARK" | tr '"' "'" >> gitlog.csv
sed -i 's/COMMENTMARK/\"/g' gitlog.csv

One can change "origin/master" in something else if needed. Explanation:

  • I have wrapped each comment in a string marker (COMMENTMARK)
  • I have replaced double quotes into single quotes
  • I have replaced the comment markers into double quotes

I had to split the escaping of the double quotes in two steps, because the GIT cannot escape characters in comments.

Having wrapped the comments in double quotes allows the presence of new line characters inside the comments.

I hope it can be useful for the community.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM