我有一个回购与文件foo在主分支。我切换到bar分支,并对foo做了一些更改。我现在如何在这个副本(尚未提交)和主分支的副本之间运行git差异?
当前回答
以下是我的工作:
Git diff master:foo foo
在过去,它可能是:
Git diff foo master:foo
其他回答
以下是我的工作:
Git diff master:foo foo
在过去,它可能是:
Git diff foo master:foo
你试图比较你的工作树和一个特定的分支名称,所以你想要这样:
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。
另外:git diff master..feature foo
因为git diff foo master:foo不能在目录上为我工作。
git difftool tag/branch filename
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别