Alexander Mills
Alexander Mills

Reputation: 100080

Git diff between local repo and origin repo

If I run these commands:

On branch dev
Your branch is ahead of 'origin/dev' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
me:cdt-now me$ git diff
me:cdt-now me$ 

so there is no diff - is that because I need to do

git diff origin/dev

?

I would have thought that git diff would default to

git diff origin/dev

but maybe not.

Upvotes: 0

Views: 740

Answers (1)

aug
aug

Reputation: 11714

By default git diff will look at your current branch and see if there are any differences. So if you made some changes on your current branch that are unstaged, a git diff would show those differences. Once you've staged changed (git add .), you won't see them unless you specify git diff --cached.

In regards to the behavior of git diff for branches, when you specify another branch, yes it should diff against it. By default if you have simply branched off of a remote branch, git diff and then specifying a branch should diff your current branch (index is the more appropriate term) and diff against the branch you specify. However, be aware that your origin/dev is your local representation of the remote branch and you need to make sure that is updated via git fetch.

Also in your case, it looks like you committed your change. A git diff against a branch should show the difference but if this is your local branch and you simply want to see the diff of your last commit again, remember you can also specify HEAD references and go back X number of commits. So to go and see the diff of your last commit, you can do git diff HEAD~1

More info on git diff.

Upvotes: 2

Related Questions