hottea
hottea

Reputation: 37

Difference between "git diff origin/somebranch" and "git diff origin somebranch"

What is the difference between these?

For example if I have just cloned a repo and there is a remotes/origin/somebranch

git checkout somebranch

make changes then add commit push

git diff origin somebranch is showing changes.

git diff origin/somebranch shows no changes.

Upvotes: 1

Views: 333

Answers (2)

Ajay
Ajay

Reputation: 3086

it will be good if you take a look at the below stack overflow question which explains what is the difference between 'origin master' and 'origin/master' .

In Git, what is the difference between origin/master vs origin master?

and this link which explains how git tries to resolve the symbolic links

https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html

so here

git diff origin/somebranch

is trying to compare the current index to origin/somebranch , which should have the same data as you have already committed your changes. ( pushing to the remote really doesn't make much difference as diff will not try to fetch data from the remote.)

on the other hand

 git diff origin somebranch

tries to compare the origin's HEAD (refer number :6 from the second link) with the branch somebranch (number:4 from the second link) . Normally a remotes head will be pointing to master branch ,so here it can be showing the differences between the master branch and the branch that you have mentioned

Upvotes: 0

Andrew C
Andrew C

Reputation: 14863

Once you have done git push that should make origin/somebranch and somebranch point to the same SHA, so I would not expect git diff origin/somebranch to show any differences, since that is diffing against HEAD, which is somebranch. Try it after you commit and before you push to see your changes.

The reason that git diff origin somebranch is showing changes is due to how git is interpreting origin. I'm guessing it is interpreting it to mean origin/HEAD from when it fetched the remote, and that the remote HEAD was something other than somebranch. You can verify this by

git rev-parse origin
git name-rev origin

or from your top level directory and presuming your refs aren't packed

cat .git/refs/remotes/origin/HEAD

Upvotes: 2

Related Questions