git 两个不同文件之间的git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16683121/
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
git diff between two different files
提问by MiJyn
In HEAD
(the latest commit), I have a file named foo
. In my current working tree, I renamed it to bar
, and also edited it.
在HEAD
(最新提交)中,我有一个名为foo
. 在我当前的工作树中,我将其重命名为bar
,并对其进行了编辑。
I want to git diff
foo
in HEAD
, and bar
in my current working tree.
我想git diff
foo
在HEAD
,并bar
在我当前的工作树中。
回答by Steven Wexler
Check out the --find-renames
option on git-diff
at https://www.kernel.org/pub/software/scm/git/docs/git-diff.html
退房的--find-renames
选择上git-diff
,在https://www.kernel.org/pub/software/scm/git/docs/git-diff.html
Or specify the paths explicitly:
或者明确指定路径:
git diff HEAD:full/path/to/foo full/path/to/bar
git diff HEAD:full/path/to/foo full/path/to/bar
(Credit goes to twaggs from Git: How to diff two different files in different branches?)
(归功于Git 的twaggs :如何区分不同分支中的两个不同文件?)
回答by mh sattarian
I believe using --no-index
is what you're looking for:
我相信 using--no-index
是您正在寻找的:
git diff [<options>] --no-index [--] <path> <path>
as mentioned in the git manual:
如 git 手册中所述:
This form is to compare the given two paths on the filesystem. You can omitthe
--no-index
option when running the command in a working tree controlled by Git and at least one of the paths points outsidethe working tree, or when running the command outsidea working tree controlled by Git.
这种形式是比较文件系统上给定的两个路径。在 Git 控制的工作树中运行命令并且至少有一个路径指向工作树之外时,或者在Git 控制的工作树之外运行命令时,您可以 省略该
--no-index
选项。
回答by camjocotem
If you are using tortoise git you can right-click on a file and git a diff by: Right-clicking on the first file and through the tortoisegit submenu select "Diff later" Then on the second file you can also right-click on this, go to the tortoisegit submenu and then select "Diff with yourfilenamehere.txt"
如果您使用的是 tortoise git,您可以右键单击一个文件并通过以下方式 git diff:右键单击第一个文件并通过 tortoisegit 子菜单选择“稍后比较”然后在第二个文件上您也可以右键单击此文件,转到 tortoisegit 子菜单,然后选择“Diff with yourfilenamehere.txt”
回答by Stevie Wonder
Using PhpStorm, I just copy prev commit code and compare it with current version using built in "compare with clipboard" tool.
使用 PhpStorm,我只需复制上一个提交代码并使用内置的“与剪贴板比较”工具将其与当前版本进行比较。