Git 差异总结?

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

Git diff in summary?

git

提问by Justin Moh

With git pull, it shows a diff summary like this:

使用git pull,它会显示如下差异摘要:

Updating 6a78751..811f788
Fast-forward
 app/Http/Controllers/SaleController.php    |   7 +-
 .../views/pages/sale/create.blade.php      | 137 +++++++++++++---
 resources/views/pages/sale/index.blade.php |   4 +-
 resources/views/pages/sale/show.blade.php  |   5 +-
 4 files changed, 123 insertions(+), 30 deletions(-)

Is there a way to use commands like git diffto get similar output?

有没有办法使用git diff类似的命令来获得类似的输出?

回答by Tony Vincent

git log --statwill show the amount each file was changed.

git log --stat将显示每个文件的更改量。

git whatchangedgives some detail into the files that were modified.

git whatchanged给出了修改过的文件的一些细节。

git diff --stat <sha1> <sha2>gives the files and the amount of changes between two commits.

git diff --stat <sha1> <sha2>给出文件和两次提交之间的更改量。

git diff --stat <branch>to compare to another branch (e.g. master)

git diff --stat <branch>与另一个分支进行比较(例如 master)

回答by Paul Hicks

git diffis indeed the command you seek. In particular you want

git diff确实是您寻求的命令。特别是你想要

git diff --stat

Other similar reports are available using

其他类似的报告可使用

git diff --numstat
git diff --shortstat
git diff --dirstat
git diff --name-status

回答by VonC

Is there a way to use commands like git diff to get similar output?

有没有办法使用像 git diff 这样的命令来获得类似的输出?

With Git 2.17 (Q2 2018), there actually is, with a result a bit more complete than git diff -stat:

使用 Git 2.17(2018 年第二季度),实际上有一个比git diff -stat以下更完整的结果:

"git diff" and friends learned "--compact-summary" that shows the information usually given with the "--summary" option on the same line as the diffstat output of the "--stat" option (which saves vertical space and keeps info on a single path at the same place).

" git diff" 和朋友们了解到 " --compact-summary" 显示了通常与 " --summary" 选项一起提供的信息,与 " " 选项的 diffstat 输出位于同一行--stat(这样可以节省垂直空间并将信息保留在同一位置的单个路径上)。

See commit ddf88fa(24 Feb 2018), and commit c905cbc(01 Feb 2018) by Nguy?n Thái Ng?c Duy (pclouds).
(Merged by Junio C Hamano -- gitster--in commit 868f7d2, 14 Mar 2018)

请参阅Nguy?n Thái Ng?c Duy ( )提交的 ddf88fa(2018 年 2 月 24 日)和c905cbc(2018 年 2 月 1 日(由Junio C Hamano合并-- --868f7d2 提交中,2018 年 3 月 14 日)pclouds
gitster

diff: add --compact-summary

Certain information is currently shown with --summary, but when used in combination with --stat it's a bit hard to read since info of the same file is in two places (--stat and --summary).

On top of that, commits that add or remove files double the number of display lines, which could be a lot if you add or remove a lot of files.

--compact-summaryembeds most of --summaryback in --statin the little space between the file name part and the graph line, e.g. with commit 0433d53:

Documentation/merge-config.txt         |  4 +
builtin/merge.c                        |  2 +
...-pull-verify-signatures.sh (new +x) | 81 ++++++++++++++
t/t7612-merge-verify-signatures.sh     | 45 ++++++++
4 files changed, 132 insertions(+)

It helps both condensing information and saving some text space.

What's new in diffstat is:

  • A new 0644 file is shown as (new)
  • A new 0755 file is shown as (new +x)
  • A new symlink is shown as (new +l)
  • A deleted file is shown as (gone)
  • A mode change adding executable bit is shown as (mode +x)
  • A mode change removing it is shown as (mode -x)

Note that --compact-summarydoes not contain all the information --summaryprovides. Rewrite percentage is not shown but it could be added later, like R50%or C20%.

diff: 添加 --compact-summary

当前使用--summary 显示某些信息,但是当与--stat 结合使用时,由于同一文件的信息位于两个位置(--stat 和--summary),因此有点难以阅读。

最重要的是,添加或删除文件的提交使显示行数加倍,如果添加或删除大量文件,则显示行数可能会很多。

--compact-summary嵌入大部分--summary早在--stat文件名部分和图线,例如,与之间的空间不大 提交0433d53

Documentation/merge-config.txt         |  4 +
builtin/merge.c                        |  2 +
...-pull-verify-signatures.sh (new +x) | 81 ++++++++++++++
t/t7612-merge-verify-signatures.sh     | 45 ++++++++
4 files changed, 132 insertions(+)

它有助于压缩信息并节省一些文本空间。

diffstat 的新功能是:

  • 一个新的 0644 文件显示为 (new)
  • 一个新的 0755 文件显示为 (new +x)
  • 一个新的符号链接显示为 (new +l)
  • 删除的文件显示为 (gone)
  • 添加可执行位的模式更改显示为 (mode +x)
  • 删除它的模式更改显示为 (mode -x)

请注意,--compact-summary不包含--summary提供的所有信息 。未显示重写百分比,但可以稍后添加,例如R50%C20%