git diff在文件的工作副本和它的另一个分支上的版本之间

时间:2015-01-21 20:45:13

标签: git

我知道之前有一个类似的问题被问到并回答过,但我尝试过的任何事都不适合我。我在我的开发分支上,我想将一个文件从master分支的头部复制到我的工作目录,所以我执行以下操作:

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

复制工作正常,我可以看到文件时间戳已更新。要检查文件内容,我调用git diff

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

我仍然看到我的分支与origin/master之间存在一些差异。

我做错了什么?

(git版本1.7.9.5)

2 个答案:

答案 0 :(得分:3)

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

这会将已经提交的内容与分支区分开来,而与本地更改无关。 the git-diff documentation描述了您想要做的事情:

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

此表单用于查看工作树中相对于命名<commit>的更改。您可以使用HEAD将其与之进行比较   最新提交,或与分支名称进行比较的分支名称   不同的分支。

试试这个:

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

答案 1 :(得分:2)

git diff <my branch> origin/master -- <my relative path>说要在最后提交给你的分支和origin / master之间进行区分。来自git-diff手册页......

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

您希望在工作副本和origin / master之间进行区分。

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