gpt4 book ai didi

git - 按更改类型过滤 git diff

转载 作者:IT王子 更新时间:2023-10-29 01:23:58 25 4
gpt4 key购买 nike

有没有办法限制 git diff 更改文件?

我想查看两个提交之间的差异,但排除一个或另一个中不存在的路径(添加/删除)。以下 Perl 单行说明了我想要的大部分内容:

git diff master.. | perl -lnwe 'print unless /^(new|deleted) file/../^diff/ and not /^diff/'

但这会为新的或删除的文件留下 diff --git a/path b/path 行。另外,如果我不必解析它会更好(例如,如果任何大块包含匹配/^diff/的任何内容,也会失败)。

我尝试的另一种选择是:

git diff --name-status (args) | perl -lnwe 'print if s/^M\s+//' | xargs git diff (args) --

它的输出更好,但仍然感觉很老套。

最佳答案

您正在寻找 --diff-filter=M 以仅显示在两个分支之间M修改的文件。

来自 man git-diff

--diff-filter=[ACDMRTUXB*]

Select only files that are

  • A Added
  • C Copied
  • D Deleted
  • M Modified
  • R Renamed
  • T have their type (mode) changed
  • U Unmerged
  • X Unknown
  • B have had their pairing Broken
  • * All-or-none

Any combination of the filter characters may be used.

When * (All-or-none) is added to the combination, all paths areselected if there is any file that matches other criteria in thecomparison; if there is no file that matches other criteria, nothingis selected.

Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths.

关于git - 按更改类型过滤 git diff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6879501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com