Skip to content

Instantly share code, notes, and snippets.

@kurnakovv
Last active November 3, 2025 07:43
Show Gist options
  • Select an option

  • Save kurnakovv/87a354c5317aa282703bdd7390a7ab0d to your computer and use it in GitHub Desktop.

Select an option

Save kurnakovv/87a354c5317aa282703bdd7390a7ab0d to your computer and use it in GitHub Desktop.
Run dotnet format only for git changes (`git status` files)
# 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
@kurnakovv
Copy link
Author

kurnakovv commented Nov 3, 2025

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:
image

By running this script you will get something similar
image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment