Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is git diff origin master supposed to do?

Tags:

git

diff

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?

like image 908
Senthil Kumaran Avatar asked Mar 07 '14 20:03

Senthil Kumaran


People also ask

What does git diff origin master do?

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..

What does git origin master mean?

The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch.

What's the difference between origin master and master?

Master: This is a branch name where we first initiate git and then we use to make commits. And the changes in the master can pull/push into a remote. origin/master: This is a remote branch, which has a local branch named master on a remote named origin.

What does diff -- git do?

Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.


2 Answers

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.

like image 183
torek Avatar answered Oct 19 '22 01:10

torek


"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
like image 22
Amos Folarin Avatar answered Oct 19 '22 00:10

Amos Folarin