Skip to content

Instantly share code, notes, and snippets.

@bfichter
bfichter / commitn2s.sh
Created March 22, 2020 15:03
Bash script to make a commit excluding comments
#!/bin/bash
paths="$(git diff --name-only --cached --diff-filter=MA)"
echo "$paths" |
while IFS= read -r path; do
cp "$path" "$path.precommentstrip"
git diff --cached "$path" | awk '($1 ~ /^\+/) && (/\/\//)' | cut -c 2- |
while IFS= read -r addition; do
commentFreeAddition="$(echo "$addition" | awk -F'//' '{print $1}' | sed 's|[[:blank:]]*$||')"