git 如何显示部分或所有文件之间的差异?通用电气

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

how to show differences between some or all files? GIT

git

提问by matiit

As in the subject: how to show differences betwen some or all files?

如主题:如何显示某些或所有文件之间的差异?

Sorry i've screwed up my question. I meant differences betwen branches for one or multiple or all files.

对不起,我搞砸了我的问题。我的意思是一个或多个或所有文件的分支之间的差异。

回答by sehe

Or perhaps a bit more helpful:

或者也许更有帮助:

git diff <commit1> <commit2> -- path/to/file.cpp path/to/anotherfile.cpp path/to/subdir

You can also (in e.g. bash)

你也可以(例如在 bash 中)

git diff {<commit1>,<commit2>}:path/to/file.cpp

This way you can even

这样你甚至可以

git diff <commit1>:path/to/file.cpp <commit2>:path/to/anotherfile.cpp

which is quite insane powerful, IMHO.

这是相当疯狂的强大,恕我直言。

Replace <commit1>and <commit2>by any name of tag, branch (local or remote) or direct sha1 hash of a commit (this is known as a commit-ish)

替换<commit1><commit2>任何标签、分支(本地或远程)名称或提交的直接 sha1 哈希(这称为commit-ish

To get really funky, you can specify tree-ish or blob hashes if you want. Do something completely silly with this for a sample:

为了变得非常时髦,您可以根据需要指定树形或 blob 哈希。对于示例,用这个做一些完全愚蠢的事情:

$ git ls-tree HEAD^ | grep blob | sort -R | head -2
100644 blob 27785581e788049ac805fab1d75744dd7379735d    .gitignore
100644 blob 2821a5271ffd8e6b11bb26b8571f57e88ab81f38    TESTING

$ git diff --stat 2821a5271ffd8e6b11bb26b8571f57e88ab81f38 aa96765714a3058068c4425d801fab4b64e26066
 ...f38 => aa96765714a3058068c4425d801fab4b64e26066 |  155 +++++++++++++++++---
 1 files changed, 135 insertions(+), 20 deletions(-)

Now you won't usually do this, unless you have several versions of the 'same' file in you repo (which is iffy, if you ask me).

现在你通常不会这样做,除非你的仓库中有多个版本的“相同”文件(如果你问我,这是不确定的)。

回答by jondavidjohn

git diff

Will show you the pending modified changes of un committed files

将向您显示未提交文件的挂起修改更改

Review the docson this command for the many different ways you can use it to see the differences between files

查看有关此命令的文档,了解可以使用它查看文件之间差异的多种不同方式

回答by Alan Whitelaw

Your question is quite vauge, but i think you are looking for:

你的问题很模糊,但我认为你正在寻找:

git diff

http://www.kernel.org/pub/software/scm/git/docs/git-diff.html

http://www.kernel.org/pub/software/scm/git/docs/git-diff.html