我有一个回购与文件foo在主分支。我切换到bar分支,并对foo做了一些更改。我现在如何在这个副本(尚未提交)和主分支的副本之间运行git差异?
你试图比较你的工作树和一个特定的分支名称,所以你想要这样:
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 diff .
查看与任何其他现有分支相比较的局部更改
git diff <branch-name> .
查看特定文件的更改
git diff <branch-name> -- <file-path>
确保在开始时运行git fetch。
假设你有一个名为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添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别