0

I am new to GIT commands and having tough time with it :(. My requirement is to use GIT command in PowerShell and do some logic. How to combine GIT diff with commitID and folder path?

This works-

>$(git diff --name-status HEAD~1..HEAD ROOT/subFolder)

output: M ROOT/subFolder/file.txt -----This is what I want but using commit id

These commands don't work

>$(git diff --name-status 5d658f9e ROOT/subFolder)       **with commit id**

>$(git diff --name-status 5d658f9e..HEAD -- ROOT/subFolder)  **with commit id & HEAD**

>$(git diff --name-status HEAD --diff-filter=ADMR -- ROOT/subFolder) **with commit id**

why the 1st command only works and others don't work?

James Z
  • 12,209
  • 10
  • 24
  • 44
Nazeer
  • 3
  • 2
  • 1
    What error message do you get when you try the bottom 3 commands? – nofinator May 26 '22 at 16:27
  • Well, at least it is strange. It works (on my machine :)). Using latest Powershell Core, but tried it successfully in Windows Powershell 5.1. `❯ $(git diff --name-status 10ca29..HEAD -- .\src\AzureLogging)` `M src/AzureLogging/Controllers/Worker.cs` – Stano Peťko May 26 '22 at 16:50
  • 1
    Be aware that PowerShell has a bad habit of messing with input and output streams, converting output to UTF-16-LE for instance. I avoid Windows so I am not up on all the details, but see, e.g., [this question](https://stackoverflow.com/q/19388342/1256452). On the Git side, be aware that `git diff` is a *user oriented* command that obeys user configuration settings. For scripting purposes you should generally run `git diff-tree` or `git diff-index` or `git diff-files` or the like. Unfortunately the command line options for these are rather different than for `git diff`, and harder to get right. – torek May 26 '22 at 19:22

1 Answers1

0

Thanks everyone.

Now, for me the 2 commands works as expected:

$(git diff --name-status 5d658f9e..HEAD -- ROOT/subFolder) with commit id & HEAD

$(git diff --name-status 5d658f9e..HEAD --diff-filter=ADMR -- ROOT/subFolder) with commit id & HEAD

Nazeer
  • 3
  • 2