Last active
November 3, 2025 07:43
-
-
Save kurnakovv/87a354c5317aa282703bdd7390a7ab0d to your computer and use it in GitHub Desktop.
Run dotnet format only for git changes (`git status` files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get git current changes (file names) | |
| $files = git status --porcelain | ForEach-Object { | |
| $_.Substring(3) | |
| } | |
| if ($files.Count -eq 0) { | |
| Write-Host "No diff" | |
| exit | |
| } | |
| # Concat file names to string with space separator | |
| $filesString = $files -join " " | |
| Write-Host "Running formatting..." | |
| Write-Host "---------------------" | |
| Write-Host "dotnet format --include $files --verbosity detailed --no-restore" | |
| Write-Host "---------------------" | |
| dotnet format --include $files --verbosity detailed --no-restore |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
This script allows you to run dotnet format only for those files that have been changed in the project (git changes)
Instruction
For example, you changed some files in the project:

By running this script you will get something similar

Links
If you need a script that runs formatting only for current git branch, here it is
If you need to run formatting on save, here it is