首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将一个文件的当前工作副本与另一个分支的已提交副本进行比较

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

Stack Overflow用户
提问于 2012-02-02 21:36:30
回答 8查看 135.6K关注 0票数 184

我在主分支中有一个包含文件foo的存储库。我切换到bar分支,并对foo进行了一些更改。现在如何在此副本(尚未提交)和主分支的副本之间运行git diff

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2012-02-02 21:46:17

下面的方法对我很有效:

git diff master:foo foo

在过去,它可能是:

git diff foo master:foo

票数 181
EN

Stack Overflow用户

发布于 2013-04-02 21:52:12

您正在尝试将您的工作树与特定的分支名称进行比较,因此您需要这样:

代码语言:javascript
运行
复制
git diff master -- foo

它来自这种形式的git-diff (参见git-diff手册页)

代码语言:javascript
运行
复制
   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)选项,用于查看您已暂存的内容的差异,而不是查看工作树中的所有内容:

代码语言:javascript
运行
复制
   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.
票数 113
EN

Stack Overflow用户

发布于 2012-09-24 16:16:15

代码语言:javascript
运行
复制
git difftool tag/branch filename
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9113280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档