1

I'm using the following to create a CSV file of my commit history to be seen in Microsoft Excel.

git log --since='last month' --pretty=tformat:"%an, %s" --author=Jorge > "Jorge.csv"

The problem is that some commit subjects have commas in them. So when I use %s to get the commit subjects (AKA commit messages), the commas in them cause commit subjects to be split into different cells (e.g. the subject "Added the ability to dash, wall jump, and wall climb in the game" gets split into 3 cells in Excel but I want it to be 1 single cell).

How can I get the git log command to escape the commas inside %s so that commas show in excel instead of splitting the subject?

I want the output to be:
| Jorge | Added the ability to dash, wall jump, and wall climb in the game |
where | represents the cells in Excel

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jorge Luque
  • 435
  • 1
  • 4
  • 17
  • What is your desired output when the commit message contains commas? Should they be removed? Should they be escaped somehow? Should the entire message be quoted? – larsks Nov 18 '19 at 03:14
  • I updated my question with the desired output – Jorge Luque Nov 18 '19 at 03:21
  • "*get the commit subjects (AKA commit messages)*" Minor nitpick: a commit subject is not a commit message, only the first line of it. A commit message is a commit subject + a commit message body separated by an empty line. (Body could be further divided by empty lines). – phd Nov 18 '19 at 10:40
  • @phd I see, I'm a bit confused then. I have some commit messages that take up 4 lines, each separated by an end of line character. However, %s returns all of those 4 lines, not just the first one. Or can a commit message be composed of multiple lines while still being separate from the "body" section? – Jorge Luque Nov 18 '19 at 18:03
  • 1
    To be precise: `%s` returns the 1st *paragraph* (separated from the rest by **an empty line, i.e. 2 —TWO — end-of-line characters**) and `%b` the rest. – phd Nov 18 '19 at 18:12

2 Answers2

2

So when I use %s to get the commit subjects (AKA commit messages), the commas in them cause commit subjects to be split into different cells

It should not: you can open a csv file in Excel with a different separator (different than ',')

As shown here, you have the choice:

https://i.stack.imgur.com/BRLI8.png

So instead of "%an, %s", consider for instance ';' or tab.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

So when I use %s to get the commit subjects (AKA commit messages), the commas in them cause commit subjects to be split into different cells

That's exactly what is happening, the commas are causing subjects (or texts) to be split into different cells. It's because whatever spreadsheet processor you're using to view the file is separating them with the commas. There should be an option on how you want to separate the texts, as there is in LibreOffice Calc in Ubuntu Linux.

Since there are commas and you obviously DONOT want to separate with commas you can instead separate with semi-colon:

git log --since='last month' --pretty=tformat:"%an; %s" --author=Jorge > "Jorge.csv"

So instead of separating %an and %s with ',', you separate them with ';'. That should do the trick as well.

bijaykumarpun
  • 677
  • 4
  • 9