Stop Clicking Through Commits: Auto-Export Diffs to CSV via GitHub Actions



This content originally appeared on Level Up Coding – Medium and was authored by Sugavasilakshmisahithi

Introduction:

When working on a project with frequent commits, it can be difficult to track exactly what code has changed. To review modifications, we usually open the repository on GitHub, click through each commit, and manually inspect line changes. This process is time-consuming and inefficient, especially in fast-moving projects.

In this guide, I’ll show you a better approach: automating change tracking with GitHub Actions. By providing just a from commit ID and a to commit ID, you can generate a CSV report containing all the inserted changes (class name, line number, column number, and updated code). This saves valuable time and creates a downloadable report that’s easy to analyze.

Why This Matters

  • Faster Reviews — No need to manually open each commit in GitHub.
  • Better Traceability — CSV reports can be stored or shared with your team.
  • Automation — GitHub Actions does the heavy lifting; you just provide commit IDs.

The Approach

  1. Use git diff to compare two commits in your repository.
  2. Parse the output with awk to extract details like class name, line number, and changed code.
  3. Export results into a CSV file.
  4. Automate with GitHub Actions so the CSV is generated on demand.

Step 1: Git Diff Command

The base command to compare commits is:

git diff <FROM_COMMIT> <TO_COMMIT> -- 'force-app/**/*.cls'

This shows differences between the two commits for Apex class files.

‘force-app/**/*.cls’ is the directorary of the classes.

We only want insertions, so we filter out deletions:

git diff <FROM_COMMIT> <TO_COMMIT> -- 'force-app/**/*.cls' | grep '^+[^+]'

Step 2: Parse Changes with Awk

Here’s an example awk script that captures:

  • Class name
  • Line number
  • Column number
  • Changed line
git diff $FROM $TO -- 'force-app/**/*.cls' | gawk '
BEGIN { class=""; line=0; old="" }

/^diff --git/ { class=""; next }

/^\+\+\+ b\// {
if (match($0, /([^\/]+)\.cls$/, a)) class=a[1]
next
}

/^@@/ {
split($0, a, " ")
split(a[3], newRange, ",")
line=newRange[1]
sub(/^\+/, "", line)
old=""
next
}

/^[ ]/ { line++; old=""; next }

/^\-/ { old=substr($0,2); next }

/^\+/ {
new=substr($0,2)

# Default: first non-space
col=1
if (length(old)>0) {
for (i=1; i<=length(old) && i<=length(new); i++) {
if (substr(old,i,1)!=substr(new,i,1)) { col=i; break }
}
} else {
if (match(new,/[^ \t]/)) col=RSTART
}

print class, "Line:", line, "Col:", col, new
line++
old=""
}
'

Run this in VS Code terminal (Git Bash) → It prints CSV-formatted rows of recent changes directly.

Easily view recent code changes between commits without manual browsing.

This prints CSV-formatted rows directly to the terminal.

Step 3: GitHub Actions Workflow

Now let’s automate this with GitHub Actions.

Create a file: .github/workflows/diff-report.yml

name: Commit Diff to CSV
on:
workflow_dispatch:
inputs:
fromCommit:
description: 'Starting commit SHA'
required: true
toCommit:
description: 'Ending commit SHA'
required: true
jobs:
generate-report:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Ensure full history is available
- name: Generate CSV of Recent Changes
run: |
echo "ClassName,LineNumber,Column,Code" > diff_report.csv
FROM=${{ github.event.inputs.fromCommit }}
TO=${{ github.event.inputs.toCommit }}
git diff $FROM $TO -- 'force-app/**/*.cls' | awk '
BEGIN { class=""; line=0; old="" }
/^diff --git/ { class=""; next }
/^\+\+\+ b\// {
if (match($0, /([^\/]+)\.cls$/, a)) class=a[1]
next
}
/^@@/ {
split($0, a, " ")
split(a[3], newRange, ",")
line=newRange[1]
sub(/^\+/, "", line)
old=""
next
}
/^[ ]/ { line++; old=""; next }
/^\-/ { old=substr($0,2); next }
/^\+/ {
new=substr($0,2)
col=1
if (length(old)>0) {
for (i=1; i<=length(old) && i<=length(new); i++) {
if (substr(old,i,1)!=substr(new,i,1)) { col=i; break }
}
} else {
if (match(new,/[^ \t]/)) col=RSTART
}
if (class == "") { class="UnknownClass" }
gsub(/,/, ";", new) # avoid CSV breakage on commas
print class "," line "," col "," new
line++
old=""
}' >> diff_report.csv
echo "Generated diff_report.csv:"
cat diff_report.csv
- name: Upload CSV artifact
uses: actions/upload-artifact@v3
with:
name: commit-diff-report
path: diff_report.csv

Step 4: Running the Workflow

  1. Go to the Actions tab in your GitHub repository.
  2. Select Commit Diff to CSV workflow.
  3. Enter the fromCommit and toCommit SHA values.
  4. Run the workflow.
  5. Once finished, download the artifact named commit-diff-report.

The artifact will contain a file diff_report.csv with all the code insertions.

Example Output (CSV)

ClassName,LineNumber,ColumnNumber,ChangedLine
AccountService,42,5,public void newMethod() {
AccountService,43,9,System.debug('New Method');
AccountService,44,5,}

Benefits of This Approach

  • Automated: No manual searching through commits.
  • Shareable: The CSV file can be shared with your team or uploaded to reporting tools.
  • Customizable: You can extend this script to track deletions, file types, or even generate JSON reports.

Conclusion

Reviewing commits doesn’t have to be tedious.

By combining git diff + awk + GitHub Actions, you can:

  • Automatically generate CSV reports of changes
  • Speed up reviews and audits
  • Improve team collaboration and transparency

This workflow makes commit analysis faster, automated, and shareable — a game-changer for DevOps and CI/CD pipelines.


Stop Clicking Through Commits: Auto-Export Diffs to CSV via GitHub Actions was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding – Medium and was authored by Sugavasilakshmisahithi