git diff 同一分支上的两个文件,相同的提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13964328/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:07:30  来源:igfitidea点击:

git diff two files on same branch, same commit

git

提问by d-_-b

sorry if this question exists, I surprisingly could not find it :/

对不起,如果这个问题存在,我出人意料地找不到它:/

How can I perform a git diffbetween two files within the same branch & same commit?

如何git diff在同一分支和同一提交中的两个文件之间执行?

i.e. git diff fileA.php fileB.php

IE git diff fileA.php fileB.php

(ideally with the easy to read color coding that gitoffers....or similar to what the program BeyondCompare does!)

(理想情况下,易于阅读的颜色编码git提供了......或类似于 BeyondCompare 程序的功能!)

采纳答案by JaredMcAteer

You don't need git for that, just use diff fileA.php fileB.php(or vimdiff if you want side by side comparison)

你不需要 git,只需使用diff fileA.php fileB.php(或 vimdiff,如果你想并排比较)

回答by rzrgenesys187

If you want to use git diffon two arbitrary files you can use git diff --no-index <file_a> <file_b>. The two files do not need to be tracked in gitfor this to work.

如果要git diff在两个任意文件上使用,可以使用git diff --no-index <file_a> <file_b>. 无需跟踪这两个文件即可git使其正常工作。

回答by Pau Fracés

If the files you want to compare are in your working copy, you can use simply diffas pointed by the others, however if the files are in some revision you can specify a revision for each file

如果您要比较的文件在您的工作副本中,您可以简单地使用diff其他人指出的文件,但是如果文件在某个修订版中,您可以为每个文件指定一个修订版

git diff <revision_1>:<file_1> <revision_2>:<file_2>

as noted here: https://stackoverflow.com/a/3343506/1815446

如此处所述:https: //stackoverflow.com/a/3343506/1815446

In your case (specifying the same revision for both files):

在您的情况下(为两个文件指定相同的修订版):

git diff <revisionX>:fileA.php <revisionX>:fileB.php

回答by mvp

To make regular gnu diff look more like git diff, I would recommend these parameters:

为了使常规 gnu diff 看起来更像 git diff,我建议使用以下参数:

diff -burN file_or_dir1 file_or_dir2

(where -bignore spaces, -uunified diff, -rrecursive, -Ntreat missing files as /dev/null).

(其中-b忽略空格,-u统一差异,-r递归,-N将丢失的文件视为/dev/null)。

It works great, but still does not have colors and git-style auto-paging is virtually absent. If you want to fix both (I do), install colordiffand use it like this:

它工作得很好,但仍然没有颜色,而且几乎没有 git 风格的自动分页。如果你想修复这两个(我想),请colordiff像这样安装和使用它:

colordiff -burN file_or_dir1 file_or_dir2 | less -R

This gives output and interface that is very close to actual git diff.

这提供了非常接近实际的输出和界面git diff

回答by Matt Lacey

If you want to diff two local files in the same directory just use diff.

如果要比较同一目录中的两个本地文件,只需使用 diff。

diff fileA.php fileB.php

回答by Peter van der Does

Just use regular diff.

只需使用常规差异。

diff -Nua fileA.php fileB.php