I have created a simple PowerShell script to automate the creation of an archive containing all the files that were modified between two git tags.
It seemed to work quite well with the few tests I had done, but today a colleague complained that it wasn't adding a specific file. I started debugging it and I'm seeing a very strange behavior.
As you can see, the command I'm using to list the files modified is git diff, passing the to and from tags that I got from the PowerShell command's argument (as strings).
param(
# Git tag or commit has from which we want the patch to start
[String] $FromTag,
# Path of the patch file
[String] $PatchFilePath,
# Git tag or commit hash where to we want the patch to update to (default HEAD, current checkout)
[String] $ToTag = "HEAD"
)
...
$modifiedFiles = git diff $FromTag..$ToTag --no-commit-id --name-only --diff-filter=ACMRT
...
Testing it, I saw that the files were indeed missing. I decided to run the command manually, like this:
git diff v041.3.2..v041.3.6 --no-commit-id --name-only --diff-filter=ACMRT
Which returned the files... and got me baffled. I then tried to do the following:
$FromTag = "v041.3.2"
$ToTag = "v041.3.6"
git diff $FromTag..$ToTag --no-commit-id --name-only --diff-filter=ACMRT
Which doesn't return all the files, but a subset of them.
I've then tried to call
git diff "v041.3.2".."v041.3.6" --no-commit-id --name-only --diff-filter=ACMRT
Which gives me the exact same result as with the variables, returning only a subset of all the files that were modified.
I've tried to run that last command in a "DOS" command prompt to check if it was a git issue, but it returns the correct set of files.
There seems to be a difference on how git interprets the input when PowerShell passes it as strings, but I really don't get why and how.
Here's the full script for those interested: https://gist.github.com/Gimly/b865b0ed09f0f9fe13d12f6b0137ecfb
The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.
git-difftool invokes a diff tool individually on each file. Errors reported by the diff tool are ignored by default. Use --trust-exit-code to make git-difftool exit when an invoked diff tool returns a non-zero exit code. git-difftool will forward the exit code of the invoked tool when --trust-exit-code is used.
The "common" recommendation for command-line git on Windows is to use the "git-bash" shell. However, git works nicely from the Windows PowerShell with one small addition...
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.
Run cmd /c echo $FromTag..$ToTag
from PowerShell and you'll see a space after the first variable:
v041.3.2 ..v041.3.6
Use doublequotes to pass it as one parameter as-is (the quotes won't be passed to the program):
git diff "$FromTag..$ToTag"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With