First off, let's fix the syntax of this command:
git diff feature/BRANCH_I_AM_INTERESTED_IN...master
The reason you observed:
However, this gives me many many results. It includes many many files that were changed at a much later time...
is because you have the branches flipped. When you use the 3 dot syntax with diff
, it shows all changes on the right side since where the branches split. (Here's a quick cheat sheet for dot syntax covering both diff
and log
.)
The command you need, in order to see the changes in a PR to merge branch feature/BRANCH_I_AM_INTERESTED_IN
into master
should be:
git diff master...feature/BRANCH_I_AM_INTERESTED_IN
However, that may not be exactly what you want! That will probably work most of the time, but it doesn't work in the scenario where some of the changes on feature/BRANCH_I_AM_INTERESTED_IN
already reside on master
too. For example, maybe a bug fix on your feature branch was so important that it had to be cherry-picked over to master
to make a production hotfix ASAP. Because of this, behind the scenes the diff you see in the context of a PR may be different than the obvious 3 dot syntax diff. Since PR tools (GitHub, GitLab, AzureDevops, BitBucket, etc) are independent of Git itself, it's even possible that the diff you see varies depending on the tool you're using!
Important Note: using the branch names in the diff command, specifically master
, only works before the PR is completed. If you want to use the same command after the PR is completed, you'd need to change master
to the commit master
was pointing to before completion.
That being said, fortunately for the context of your question, once the PR is completed, it's really straight-forward to see what the exact changes were that the PR brought in without the diff command. (Note this does suggest that if you compare the diff after the PR was completed, and that differs from what the PR tool showed you before it was completed, then the PR tool was actually "wrong", or at least "misleading", and this is unfortunately pretty common!)
To see what changes a PR brought in, you simply need to diff the merge commit of a PR, with it's first-parent. Typically you could do this with with a 2 dot diff:
git diff <commit-id-of-PR-merge-commit>~1..<commit-id-of-PR-merge-commit>
(Note you should put the parent commit first in the diff command so you see it from the correct POV. If you flip them new files will appear as deletes, etc.)
Now, what if you don't have a merge commit for the PR? That would happen if the branch to be merged in was already up to date with master
, and if a fast-forward merge was allowed meaning no merge commit was created. In that case it's a little trickier because you would have to know the commit master
was on before that PR was completed. I hope that whatever PR tool you use would be able to provide that information, in a historical context, so that you can compare the two commits on master
representing before and after the PR was completed.