Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only get the name of files which changes are more than whitespaces?

Tags:

git

diff

I try to get the name of files which have changes are more than whitespaces. (In another word, I don't want the files with only whitespaces changes be listed.)

I tried "git diff --name-only -w" it doesn't work. It lists all the changed files including the whitespaces only ones.

like image 472
Enze Chi Avatar asked Sep 26 '14 00:09

Enze Chi


2 Answers

To solve this issue, I wrote a script to do it. Hope it useful to others.

#!/usr/bin/env bash

GIT_REPO_ROOT=`git rev-parse --show-toplevel`
# cd ${GIT_REPO_ROOT}

for f in `git diff --name-only`;
do 
    MY_DIFF=`git diff -w ${GIT_REPO_ROOT}/${f}`
    if [[ ! ${MY_DIFF} == "" ]];
    then
        echo ${GIT_REPO_ROOT}/${f}
    fi
done

This script reduce the result from 88 files ('git diff --name-only') to 8 files.

like image 182
Enze Chi Avatar answered Sep 20 '22 10:09

Enze Chi


Add ignore-blank-lines option. Try

git diff --name-only -w --ignore-blank-lines
like image 39
palazzo train Avatar answered Sep 19 '22 10:09

palazzo train