我有一个回购与文件foo在主分支。我切换到bar分支,并对foo做了一些更改。我现在如何在这个副本(尚未提交)和主分支的副本之间运行git差异?


当前回答

另外:git diff master..feature foo

因为git diff foo master:foo不能在目录上为我工作。

其他回答

同样有效的方法:

git diff master ./relative-path-to-foo

查看本地更改与当前分支的比较

git diff .

查看与任何其他现有分支相比较的局部更改

git diff <branch-name> .

查看特定文件的更改

git diff <branch-name> -- <file-path>

确保在开始时运行git fetch。

git diff mybranch master -- file

应该也有用

git difftool tag/branch filename

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

git diff master -- foo

它来自于git-diff的这种形式(参见git-diff manpage)

   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.

供你参考,还有一个——cached (aka - staging)选项用于查看你已经staging的东西的差异,而不是你工作树中的所有东西:

   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.