我有一个回购与文件foo在主分支。我切换到bar分支,并对foo做了一些更改。我现在如何在这个副本(尚未提交)和主分支的副本之间运行git差异?
当前回答
查看本地更改与当前分支的比较
git diff .
查看与任何其他现有分支相比较的局部更改
git diff <branch-name> .
查看特定文件的更改
git diff <branch-name> -- <file-path>
确保在开始时运行git fetch。
其他回答
以下是我的工作:
Git diff master:foo foo
在过去,它可能是:
Git diff foo master:foo
另外:git diff master..feature foo
因为git diff foo master:foo不能在目录上为我工作。
git difftool tag/branch filename
假设你有一个名为master的分支和一个名为feature的分支,你想检查一个名为my_file的特定文件,然后:
git diff master..feature /Path/to/my_file显示my_file在master分支和feature分支上的提交版本之间的差异。 git diff master——/Path/to/my_file显示了工作目录(非阶段性文件)和my_file的分支master之间的差异。
你试图比较你的工作树和一个特定的分支名称,所以你想要这样:
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.
推荐文章
- 将文件的当前工作副本与另一个分支提交的副本区别对待
- 配置Git接受特定https远程的特定自签名服务器证书
- 如何将一个特定的提交从一个分支合并到Git中的另一个分支?
- 通过SSH配置Git登录一次
- 从pull请求中删除一个修改过的文件
- 如何使用Git恢复
- 如何提交没有变化和新的消息?
- 找到Git分支创建者
- 下载GitHub项目的最快方式
- git索引到底包含什么?
- 以树形输出git分支
- 如何点Go模块的依赖在Go。Mod到回购中的最新提交?
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突