Question

From a git branch, a colleague of mine ran

git diff origin master

What is it supposed supposed to do? What does origin separately point to?

This is related, but not covered in In Git, what is the difference between origin/master vs origin master?

Was it helpful?

Solution

This form of git diff just takes two revision specifiers, as described in gitrevisions.

In this case origin is most likely to match item 6:

  1. otherwise, refs/remotes/<refname>/HEAD if it exists.

So this means the same as git diff origin/HEAD master: resolve origin/HEAD to a commit-ID, resolve master to a commit-ID, and diff the two commits.

Run:

git rev-parse origin

to see how the resolution works.

OTHER TIPS

"origin" points to the "remote", typically where you cloned the repository from, see

$ git remote -v show

But specifically in answer to your question "git diff origin master" is equiv. to this:

$ git diff origin/HEAD master 

origin/HEAD to the branch pointed to by HEAD reference on the remote. Which was the checked out branch at last pull.

Take a look at your commit graph, which will show you where all your references are (--decorate)

$ git log --oneline --graph --all --decorate

It is equivalent to

git diff origin/HEAD master

It shows the changes between the tips of origin/HEAD and the master branches. You can achieve the same with following commands:

  • git diff origin/HEAD master
  • git diff origin/HEAD..master

Usually origin points to the source from where you cloned your repository.

It depends... if origin and master are branches, it shows the difference between them. When looking over explanations, they usually use origin to stand for the original (upstream, official, whatever) branch, and master for the branch you are working on. I.e., "show me what changed with respect to the original version."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top