I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what’s different. Is there a way to do this?
To be clear I’m not looking for a compare tool (I use Beyond Compare). I’m looking for a Git diff command that will allow me to compare the master version to my current branch version to see what has changed. I’m not in the middle of a merge or anything. I just want to say something like
git diff mybranch/myfile.cs master/myfile.cs
git diffcan show you the difference between two commits:Or, equivalently:
Note you must specify the relative path to the file. So if the file were in the src directory, you’d say
src/myfile.csinstead ofmyfile.cs.Using the latter syntax, if either side is
HEADit may be omitted (e.g.,master..comparesmastertoHEAD).You may also be interested in
mybranch...master(fromgit diffdocumentation):In other words, this will give a diff of changes in
mastersince it diverged frommybranch(but without new changes since then inmybranch).In all cases, the
--separator before the file name indicates the end of command line flags (mind the space between the separator and the filename). This is optional unless Git will get confused if the argument refers to a commit or a file, but including it is not a bad habit to get into. See Dietrich Epp’s answer to Meaning of Git checkout double dashes for a few examples.The same arguments can be passed to
git difftoolif you have one configured.