Find changed PowerShell files in Git
Documentation: Microsoft Learn
git diff with --name-only prints paths instead of patch content, and the pathspec arguments after the double dash restrict output to ps1 and psm1 files.
The script
Show reference output
Script reader
Inspect before you run
This is the page's actual command example. The browser does not execute it or contact a device, repository or API.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
git diff --name-only -- "*.ps1" "*.psm1"- Stage 1git
Positional values or no named parameters
How it works
git diff with --name-only prints paths instead of patch content, and the pathspec arguments after the double dash restrict output to ps1 and psm1 files. What comes back is a plain list of relative paths that PowerShell can consume as strings.
Adapting it
Compare against a branch rather than the working tree by supplying a revision range such as origin/main...HEAD, which is what a pull request check actually needs to examine.
Requirements
Git available on the path and the session running inside a repository.
If the result is unexpected
The changed-files list misses edits or includes unrelated files.
Working-tree, staged and committed differences are separate Git comparisons.
- Identify the comparison boundary and inspect untracked files separately from tracked diffs.
Validate the result
The list matches the chosen working-tree or commit comparison.
Keep the check reliable
State the base revision and whether untracked files are included before running checks on the list.