git 将文件的当前工作副本与另一个分支的提交副本进行比较
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9113280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
diff current working copy of a file with another branch's committed copy
提问by Dogbert
I have a repo with file foo
in the master branch. I switched to bar branch and made some changes to foo
. How can I now run a git diff
between this copy (which isn't committed yet) and the copy of the master branch?
我foo
在 master 分支中有一个带有文件的仓库。我切换到 bar 分支并对foo
. 我现在如何git diff
在此副本(尚未提交)和 master 分支的副本之间运行 a ?
采纳答案by Mark Longair
The following works for me:
以下对我有用:
git diff master:foo foo
git diff master:foo foo
In the past, it may have been:
在过去,它可能是:
git diff foo master:foo
git diff foo master:foo
回答by Jordan Brough
You're trying to compare your working tree with a particular branch name, so you want this:
您正在尝试将您的工作树与特定分支名称进行比较,因此您需要:
git diff master -- foo
Which is from this form of git-diff (see the git-diff manpage)
这是来自这种形式的 git-diff (请参阅 git-diff 联机帮助页)
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.
FYI, there is also a --cached
(aka --staged
) option for viewing the diff of what you've staged, rather than everything in your working tree:
仅供参考,还有一个--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.
回答by ArtBIT
Also: git diff master..feature foo
还: git diff master..feature foo
Since git diff foo master:foo
doesn't work on directories for me.
因为git diff foo master:foo
不适用于我的目录。
回答by Adir
git difftool tag/branch filename
回答by Naoise Golden
git diff mybranch master -- file
should also work
也应该工作