简体   繁体   English

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

[英]git diff two files on same branch, same commit

sorry if this question exists, I surprisingly could not find it :/ 对不起,如果这个问题存在,我出乎意料地找不到它:/

How can I perform a git diff between two files within the same branch & same commit? 如何在同一分支和同一提交中的两个文件之间执行git diff

ie git diff fileA.php fileB.php git diff fileA.php fileB.php

(ideally with the easy to read color coding that git offers....or similar to what the program BeyondCompare does!) (理想情况下, git提供易于阅读的颜色编码......或类似于BeyondCompare程序所做的!)

If you want to use git diff on two arbitrary files you can use git diff --no-index <file_a> <file_b> . 如果你想在两个任意文件上使用git diff ,你可以使用git diff --no-index <file_a> <file_b> The two files do not need to be tracked in git for this to work. 不需要在git跟踪这两个文件以使其工作。

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

If the files you want to compare are in your working copy, you can use simply diff as 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

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 -b ignore spaces, -u unified diff, -r recursive, -N treat missing files as /dev/null ). (其中-b忽略空格, -u unified diff, -r recursive, -N将丢失的文件视为/dev/null )。

It works great, but still does not have colors and git-style auto-paging is virtually absent. 它工作得很好,但仍然没有颜色,几乎没有git风格的自动分页。 If you want to fix both (I do), install colordiff and use it like this: 如果你想修复两个(我这样做),请安装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

如果要在同一目录中区分两个本地文件,只需使用diff。

diff fileA.php fileB.php

只需使用常规差异。

diff -Nua fileA.php fileB.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM