Detect Changed Files with git
There are numerous reasons to want to know which files have been added or modified in a git repository, one of which is your text editor highlighting those files. Another use case is running tasks against only files which are presently changed, like lint or other validation routines.
So how can we identify files which are added or changed? Like this:
git ls-files --others --exclude-standard ; git diff-index --name-only --diff-filter=d HEAD ;
And if you only want to run a routine on a certain portion of files, you can use a regular expression to do so:
{ git ls-files --others --exclude-standard ; git diff-index --name-only --diff-filter=d HEAD ; } | grep --regexp='[.]js$'
The MetaMask team uses the following to run linting on only changed files:
{ git ls-files --others --exclude-standard ; git diff-index --name-only --diff-filter=d HEAD ; } | grep --regexp='[.]js$' | tr '\\n' '\\0' | xargs -0 eslint --fix
Tricks like this are so useful and reliable; you put them in place once and don't consciously think about them again -- and that's OK. Set it and forget it!