Batch processing

All files in a repository

Occasionally, you may want to change all files in your repository or those that match a pattern. This is possible with the combination of git ls-files and xargs:

$ git ls-files -z | xargs -0 COMMAND

change all files in a repository.

$ git ls-files -z -- "*.SUFFIX" | xargs -0 COMMAND

only changes the files with a specific file extension.

-z, -0

uses the zero-byte separator.

Example

$ git ls-files -z -- ‘*.py’ | xargs -0 git update-index --chmod=+x

changes the permissions for all files with the suffix .py from 100644 to 100755, if necessary, so that they become executable.

All files changed in the working or staging area

git diff --name-only

outputs the files that are managed by Git and have been changed in the working area.

git diff --staged --name-only

outputs the files added to the staging area.

git diff --staged --name-only "*.SUFFIX"

also filters for a specific file extension.

Example

pytest $(git diff --staged --name-only "tests/test_*.py")

calls pytest to execute only those test modules that have been changed in the working directory.