HEKTO
HEKTO

Reputation: 4191

git diff between working copy of the file and its version on another branch

I know a similar question was asked and answered before, but nothing I tried works for me. I'm on my development branch and I want to copy a single file from the head of master branch to my working directory, so I do the following:

git checkout origin/master -- <my relative path>

The copying works fine, I can see the file timestamp updated. To check the file content I call the git diff:

git diff <my branch> origin/master -- <my relative path>

and I still see some differences between my branch and origin/master.

What am I doing wrong?

(git version 1.7.9.5)

Upvotes: 2

Views: 3579

Answers (2)

Schwern
Schwern

Reputation: 164639

git diff <my branch> origin/master -- <my relative path> says to diff between what was last committed to your branch and origin/master. From the git-diff man page...

   git diff [--options] <commit> [--] [<path>...]
       This form is to view the changes you have in your working tree relative to the
       named <commit>. You can use HEAD to compare it with the latest commit, or a
       branch name to compare with the tip of a different branch.

   git diff [--options] <commit> <commit> [--] [<path>...]
       This is to view the changes between two arbitrary <commit>.

You want to diff between the working copy and origin/master.

git diff origin/master -- <my relative path>

Upvotes: 3

Gordon Gustafson
Gordon Gustafson

Reputation: 41209

git diff <my branch> origin/master -- <my relative path>

This will diff what has been committed to the branches and has nothing to do with your local changes. the git-diff documentation describes what you want to do:

git diff [--options] <commit> [--] [<path>…]

This form is to view the changes you have in your working tree relative to the named <commit>. You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.

Try this:

git diff origin/master -- <my relative path>

Upvotes: 6

Related Questions