1

In git, if we want to exclude a file from diff output (on bash) we do something like follows:

git diff -- !(file.txt)

But this is disallowed in powershell. Hence is there a way to achieve this in the powershell prompt?

mklement0
  • 382,024
  • 64
  • 607
  • 775
deostroll
  • 11,661
  • 21
  • 90
  • 161

1 Answers1

1

Simply single-quote your argument:

git diff -- '!(file.txt)'

Single-quoting makes PowerShell treat the string literally and prevents it from interpreting chars. such as ( as its own metacharacters.

Before invoking the target program, PowerShell re-quotes arguments if and as needed, behind the scenes; that is:

  • It encloses an argument in "..." if it contains whitespace, and also in certain, less common scenarios (see link below).

  • It passes it without quotes otherwise.

Note: There are pitfalls associated with this invisible re-quoting - see this answer.

mklement0
  • 382,024
  • 64
  • 607
  • 775