Skip to content

Instantly share code, notes, and snippets.

@dualbus
Created March 16, 2015 18:26
Show Gist options
  • Save dualbus/d4d4c4a7ff8b5a6b665b to your computer and use it in GitHub Desktop.
Save dualbus/d4d4c4a7ff8b5a6b665b to your computer and use it in GitHub Desktop.
#!/bin/bash
IFS= read -rd '' index_filter <<\Command
git ls-files -s | \
awk '
BEGIN { FS="\t" }
$2 ~ /(^|\/)-i$/ {next}
$2 ~ /Makefile$/ {next}
$2 ~ /[#~]$/ {next}
$2 ~ /\.(0|aux|bt|bts)$/ {next}
$2 ~ /\.(cp|cps|dvi|fn)$/ {next}
$2 ~ /\.(fns|html)$/ {next}
$2 ~ /\.(info|kylog|pg)$/ {next}
$2 ~ /\.(old|orig|save)$/ {next}
$2 ~ /\.(ps|rw|rws)$/ {next}
$2 ~ /\.(toc|tp|vr|vrs)$/ {next}
$2 ~ /\/[._]/ {next}
$2 ~ /^_/ {next}
$2 ~ /^autom4te\.cache\// {next}
$2 ~ /^configure$/ {next}
$2 ~ /^parser-built$/ {next}
$2 ~ /^y\.tab\.[ch]$/ {next}
1
' | \
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && \
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
Command
IFS= read -rd '' commit_filter <<\Command
git_commit_non_empty_tree "$@"
Command
IFS= read -rd '' msg_filter <<\Command
cat
chlog=$(
{
git log -p -n1 "$GIT_COMMIT" -- CWRU/CWRU.chlog | \
awk '/^@@/,0{if(/^\+/){print substr($0, 2)}}'
} 2>/dev/null
)
if [ -n "$chlog" ]; then
printf '\n%s\n' "$chlog"
fi
Command
git filter-branch -f \
--index-filter "$index_filter" \
--commit-filter "$commit_filter" \
HEAD
git filter-branch -f \
--msg-filter "$msg_filter" \
HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment