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



我在master分支中有一个带有文件foo的repo。我转到酒吧分店,对foo做了一些更改。现在如何在这个副本(尚未提交)和主分支的副本之间运行git diff

以下对我有效:

git diff master:foo foo

在过去,它可能是:

git diff foo master:foo

您正试图将工作树与特定的分支名称进行比较,因此您需要以下内容:

git diff master -- foo

它来自这种形式的gitdiff(请参阅gitdiff手册页)

   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(也称为--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 difftool tag/branch filename

还有:git diff master..feature foo

由于git diff foo master:foo对我来说不适用于目录。

git diff mybranch master -- file

也应该工作

什么也有效:

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

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

git diff .

查看本地更改与任何其他现有分支的比较

git diff <branch-name> .

查看特定文件的更改

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

确保一开始就运行git fetch

假设您有一个名为masterfeature的分支,并且您想要检查一个名为主my_file的特定文件,那么:

  1. CCD_ 14示出了分支masterfeature上的my_file的已提交版本之间的差异
  2. git diff master -- /Path/to/my_file显示了工作目录(未暂存的文件)和my_file的分支master之间的差异

相关内容

最新更新