0

Running git diff origin/integration...origin/dev-userX -- path/to/file.cpp produces, in part:

--- a/path/to/file.cpp
+++ b/path/to/file.cpp
@@ -3,14 +3,12 @@
 #include "foo.h"
 #include "bar.h"
+#include <io.h>

But if I look directly in the pushed branches on github.com both files contain #include <io.h>

Questions:

  1. Why am I seeing this?
  2. Does the 'origin' syntax always mean look at the remote branch, NOT the local one?
  3. Will the 'origin' syntax work even if neither has ever been pulled / fetched or brought locally by any means?

Thanks

torek
  • 448,244
  • 59
  • 642
  • 775
chup
  • 69
  • 1
  • 7
  • 2
    Your local refs could be off. `git fetch` and retry. `origin/somebranch` is the local image of what's been fetched for `somebranch` last time you fetched/pulled `origin` (`git fetch` without any parameters implies `--all`). – Romain Valeri Jan 13 '22 at 15:04
  • 1
    If fetching doesn't fix it, it's possible the file was changed on both branches after they split (merge-base commit). Try your command with 2 dots to see if there is still *that* change. – TTT Jan 13 '22 at 15:28
  • local refs? fetch? doesn't 'origin' mean I dont need it locally? and '..' 2 dots shows nothing, so that is likely what I want? What is that doing? – chup Jan 13 '22 at 15:45

1 Answers1

3

Imagine your graph looks like this:

A   B
 \ /
  X

Suppose commit A is your branch origin/integration and commit B is your branch origin/dev-userX. If your file at commit X doesn't have the line "#include <io.h>", but each of the commits A and B both added that line, then you would witness what you're seeing. (And based on the comments this appears to be the case.)

When you diff with 3 dots (git diff A...B), you are basically saying:

Show me the changes between X and B.

When you use 2 dots (git diff A..B) you are basically saying:

Show me the changes between A and B.

More info here, and specifically my summary answer.

Regarding your question about "origin", branches starting with origin represent your "remote tracking branches". These are essentially copies of the branches on your remote repository (wherever it is hosted) based on the last time you fetched. Every time you fetch, you connect to the remote repo and update your local copy of those remote branches.

TTT
  • 22,611
  • 8
  • 63
  • 69
  • So does using origin/branch mean look on the server? if it does then why do I need to fetch? Can't the server figure it out? If it doesn't then why require it on the command line? – chup Jan 14 '22 at 14:49
  • @chup That may not have been clear in the last paragraph of the answer. No, referencing `origin` does not connect to the server. You can be completely offline and still reference your copy of branches starting with `origin`. When you fetch, you are updating your copy of those branches from the server. As for why you should use `origin` from the command line, it's so you don't have to checkout the branch first. For example, the first time you checkout `main` it will be the same as your `origin/main`, then tomorrow you fetch, `origin/main` is up to date with the server but `main` is out of date. – TTT Jan 14 '22 at 15:49