A colleague of mine asked me whether I knew how to compare 2 branches in Git outputting only the filenames, but ignoring files with only whitespace changes.
git diff --ignore-space-at-eol -b -w --name-only
But I was quite surprised to see files which only had whitespace changes showing up in the output. So I suggested working around the strange Git behaviour like this:
git diff --ignore-space-at-eol -b -w | grep ^diff
Which filters the output of the full diff, giving lines like:
diff --git a/non-whitespace.txt b/non-whitespace.txt
diff --git a/non-whitespace2.txt b/non-whitespace2.txt
He further improved on this by removing the a/ b/ prefix and using awk to extract only the filename for each line:
git diff --ignore-space-at-eol -b -w --no-prefix | grep ^diff | awk '{print $3}'
Giving a nice output:
non-whitespace2.txt
No comments:
Post a Comment