按更改类型过滤 git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6879501/
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
Filter git diff by type of change
提问by benizi
Is there a way to limit git diff
to changed files?
有没有办法限制git diff
更改的文件?
I'd like to see the differences between two commits, but exclude paths that don't exist in one or the other (additions/deletions). The following Perl one-liner illustrates most of what I want:
我想看看两个提交之间的差异,但排除一个或另一个中不存在的路径(添加/删除)。以下 Perl 单行代码说明了我想要的大部分内容:
git diff master.. | perl -lnwe 'print unless /^(new|deleted) file/../^diff/ and not /^diff/'
But that leaves diff --git a/path b/path
lines for the files that were new or deleted. Plus it'd be much nicer if I didn't have to parse (also fails if any hunk contains anything matching /^diff/, for example).
但这留下diff --git a/path b/path
了新文件或删除文件的行。另外,如果我不必解析它会更好(例如,如果任何大块包含匹配 /^diff/ 的任何内容也会失败)。
Another alternative I tried was:
我尝试的另一种选择是:
git diff --name-status (args) | perl -lnwe 'print if s/^M\s+//' | xargs git diff (args) --
Its output is better, but it still feels hackish.
它的输出更好,但仍然感觉很hackish。
回答by zen
You are looking for --diff-filter=M
to show only files *M*odified between the two branches.
您正在寻找--diff-filter=M
仅显示两个分支之间的* M*odified文件。
From man git-diff
从 man git-diff
--diff-filter=[ACDMRTUXB*]
Select only files that are
A
AddedC
CopiedD
DeletedM
ModifiedR
RenamedT
have their type (mode) changedU
UnmergedX
UnknownB
have had their pairing Broken*
All-or-noneAny combination of the filter characters may be used.
When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.
--diff-filter=[ACDMRTUXB*]
仅选择符合以下条件的文件
A
添加C
已复制D
已删除M
修改的R
重命名T
改变他们的类型(模式)U
未合并X
未知B
已经有他们的配对破碎*
全有或全无可以使用过滤器字符的任何组合。
当在组合中添加*(All-or-none)时,如果在比较中存在匹配其他条件的文件,则选择所有路径;如果没有符合其他条件的文件,则不选择任何内容。
回答by VonC
As Git 2.10 (Q3 2016) will remind us, there is an easier way to "show everything except added/deleted files." (actually since Git 1.8.5, July 2013)
正如 Git 2.10(2016 年第 3 季度)将提醒我们的那样,有一种更简单的方法可以“显示除添加/删除的文件之外的所有内容”。(实际上从 Git 1.8.5 开始,2013 年 7 月)
git diff --diff-filter=ad master..
See commit 16726cf(14 Jul 2016) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
--in commit 2f8c654, 08 Aug 2016)
请参阅Junio C Hamano() 的commit 16726cf(2016 年 7 月 14 日)。(由Junio C Hamano合并-- --在commit 2f8c654,2016 年 8 月 8 日)gitster
gitster
diff
: documentdiff-filter
exclusionIn v1.8.5 days, 7f2ea5f (
diff
: allow lowercase letter to specify what change class to exclude, 2013-07-17)taught the "--diff-filter
" mechanism to take lowercase letters as exclusion, but we forgot to document it.
diff
: 文件diff-filter
排除在 v1.8.5 天,7f2ea5f(
diff
:允许小写字母指定要排除的更改类,2013-07-17)教导“--diff-filter
”机制将小写字母作为排除,但我们忘记记录它。
So the documentation on diff-options
now (finally) includes:
所以现在(最终)的文档diff-options
包括:
These upper-case letters can be downcased to exclude.
E.g.--diff-filter=ad
excludes added and deleted paths.
这些大写字母可以小写以排除。
例如,--diff-filter=ad
排除添加和删除的路径。
回答by Lily Ballard
You can use the --diff-filter flag to do precisely this. git diff --diff-filter=CMRTUXB master..
should show everything except added/deleted files.
您可以使用 --diff-filter 标志来精确地做到这一点。git diff --diff-filter=CMRTUXB master..
应该显示除添加/删除文件之外的所有内容。
回答by iwg
To see all modified and new files you can use
要查看您可以使用的所有修改过的和新的文件
git diff --name-only --diff-filter=ACMR PREV_VERSION master
PREV_VERSION
is the hash of your first commit.
PREV_VERSION
是你第一次提交的哈希值。
To get an export as zip you can use this code
要导出为 zip,您可以使用此代码
git archive --output=export.zip HEAD $(git diff --name-only --diff-filter=ACMR PREV_VERSION HEAD)
Note: .gitignore
is not in export.zip
注意:.gitignore
不在export.zip
回答by Krzysztof Stankiewicz
I've used Notepad++ (Windows), and these regular expressions to filter out extension types and certain paths from a diff file.
我已经使用 Notepad++ (Windows) 和这些正则表达式从 diff 文件中过滤掉扩展类型和某些路径。
^Index.*\.(dll|pdb|exe|txt|zip|log|ism|resx|tlog|htm|lib)$[\s\S.]*?^Index
^Index: Shared/.+$[\s\S.]*?^Index
^Index: Next/source/Utility/.+$[\s\S.]*?^Index
Only problem is, when it reaches the end. You have to 'ctrl+home' and go again until it finds nothing.
唯一的问题是,当它到达终点时。你必须'ctrl+home'然后再去,直到它什么也没找到。
(Replace whats found with 'Index')
(用“索引”替换找到的内容)