Skip to content

Instantly share code, notes, and snippets.

@bfichter
bfichter / commitn2s.sh
Created Mar 22, 2020
Bash script to make a commit excluding comments
View commitn2s.sh
#!/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:]]*$||')"