将文件的当前工作副本与另一个分支的提交副本进行比较

我有一个在主分支文件foo回购。 我切换到酒吧分支,并对foo进行了一些更改。 我现在怎么能在这个副本(还没有提交)和主分支的副本之间运行一个git diff

以下为我工作:

git diff master:foo foo

过去,可能是:

git diff foo master:foo

你试图比较你的工作树与一个特定的分支名称,所以你想这样做:

 git diff master -- foo 

这是从这种forms的git-diff(请参阅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. 

仅供参考,还有一个 – --staged (aka --staged )选项,用于查看所执行的操作的差异,而不是工作树中的所有内容:

  git diff [--options] --cached [<commit>] [--] [<path>...] This form is to view the changes you staged for the next commit relative to the named <commit>. ... --staged is a synonym of --cached. 

另外: git diff master..feature foo

因为git diff foo master:foo不适用于我的目录。

 git difftool -v tag/branch filename 
 git diff mybranch master -- file 

也应该工作