I thought I was beginning to understand git diff.
But today I did a git diff between a commit at the tip of one branch ("A") with a commit at the tip of another ("B"), where B is a newer branch and tip of B is a newer commit than that at the tip of A. Thus I'm doing this:
> git diff [sha of tip of A] [sha of tip of B] > output_diff.txt
I'm quite baffled by the results, and in particular by the fact that lines which are present in neither commit's version of a given file (call it xxx.py) are included in the diff, with "++" at the start of the line.
These are all lines which were in branch B in the version of that file at one point ... but were then DELETED before the branch B tip commit was made. I'm baffled as to why these are there. They are of no interest to me, and make the diff file all the more difficult to understand.
Is there any way to just exclude these lines when doing a git diff? I.e. a diff based on these two commits completely in isolation.
I looked at the various diff options. Nothing jumped out as possibly doing this.
Edit: use case
My use case is that, starting from the tip of a TDD branch, I made a spur branch, what I call "wild coding", i.e. coding with no TDD. After a few commits on that I now want to see, very simply, what the differences are between the files as they are at the tip of the "wild coding" branch and the files as they are at the tip of the TDD branch, i.e. where the "wild branch" starts.
The idea being to then continue TDD development, taking inspiration from the experimental/wild coding I did in the spur branch. I quite often do this in fact for particular situations, where I feel a need to explore coding possibilities without TDD constraints.
I'm now assuming I don't really understand the purpose of git diff
. I'm assuming now that I'll simply have to checkout the wild branch, copy the directory containing the app files, and then checkout the TDD branch again. And then use a 3rd party "diff/comparison" tool to compare the state of the app files as they are in the the two respective places on the commit tree. I had assumed that git diff
could be used for that purpose. It seems that I have misunderstood.
It seems there are two (at least) forms of git diff
format: "unified" and "combined". "Combined" seems to have two characters ("+", "-" or space) at the start of lines, whereas "unified" seems to have one such. I don't know whether this might give me what I'm after ... because I can't currently work out how to deliver a git diff
using "unified" format.
I thought I was beginning to understand git diff.
But today I did a git diff between a commit at the tip of one branch ("A") with a commit at the tip of another ("B"), where B is a newer branch and tip of B is a newer commit than that at the tip of A. Thus I'm doing this:
> git diff [sha of tip of A] [sha of tip of B] > output_diff.txt
I'm quite baffled by the results, and in particular by the fact that lines which are present in neither commit's version of a given file (call it xxx.py) are included in the diff, with "++" at the start of the line.
These are all lines which were in branch B in the version of that file at one point ... but were then DELETED before the branch B tip commit was made. I'm baffled as to why these are there. They are of no interest to me, and make the diff file all the more difficult to understand.
Is there any way to just exclude these lines when doing a git diff? I.e. a diff based on these two commits completely in isolation.
I looked at the various diff options. Nothing jumped out as possibly doing this.
Edit: use case
My use case is that, starting from the tip of a TDD branch, I made a spur branch, what I call "wild coding", i.e. coding with no TDD. After a few commits on that I now want to see, very simply, what the differences are between the files as they are at the tip of the "wild coding" branch and the files as they are at the tip of the TDD branch, i.e. where the "wild branch" starts.
The idea being to then continue TDD development, taking inspiration from the experimental/wild coding I did in the spur branch. I quite often do this in fact for particular situations, where I feel a need to explore coding possibilities without TDD constraints.
I'm now assuming I don't really understand the purpose of git diff
. I'm assuming now that I'll simply have to checkout the wild branch, copy the directory containing the app files, and then checkout the TDD branch again. And then use a 3rd party "diff/comparison" tool to compare the state of the app files as they are in the the two respective places on the commit tree. I had assumed that git diff
could be used for that purpose. It seems that I have misunderstood.
It seems there are two (at least) forms of git diff
format: "unified" and "combined". "Combined" seems to have two characters ("+", "-" or space) at the start of lines, whereas "unified" seems to have one such. I don't know whether this might give me what I'm after ... because I can't currently work out how to deliver a git diff
using "unified" format.
1 Answer
Reset to default 0XY problem? Or just the wrong tool for the job?
This might prove useful to someone. It seems that what I really want is the BASH command diff
(available in Cygwin or WSL in a Windows context).
check out and copy the newer commit (or a relevant directory of it) to a temporary directory (here D:/temp/core)
check out the older commit
do something like this:
>diff -Nru src/core d:/temp/core > temp.diff
Options: N
: new files also included; r
: recursive; u
: "unified" format
git diff
, or possiblygit difftool
(orgit difftool -d
for a directory view). You may want to also use--diff-filter
, checkgit help diff
for its usage. – LeGEC Commented Mar 13 at 6:36