按更改类型过滤 git diff
有没有办法将 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) --
它的输出更好,但仍然感觉很hackish。
Is there a way to limit git diff
to changed files?
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:
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).
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找
--diff-filter=M
以仅显示两个分支之间M修改的文件。来自
man git-diff
You are looking for
--diff-filter=M
to show only files Modified between the two branches.From
man git-diff
正如 Git 2.10(2016 年第 3 季度)提醒我们的那样,有一种更简单的方法可以“显示除添加/删除的文件之外的所有内容”。 (实际上自 Git 1.8.5,2013 年 7 月起)
请参阅 commit 16726cf(2016 年 7 月 14 日)通过 Junio C Hamano (
gitster
)。(由 Junio C Hamano --
gitster
-- 合并于 提交2f8c654,2016 年 8 月 8 日)所以 有关
diff-options 的文档< /code>
现在(最终)包括:
请务必使用 Git 2.36(2022 年第 2 季度)。
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)
See commit 16726cf (14 Jul 2016) by Junio C Hamano (
gitster
).(Merged by Junio C Hamano --
gitster
-- in commit 2f8c654, 08 Aug 2016)So the documentation on
diff-options
now (finally) includes:Make sure to use Git 2.36 (Q2 2022).
要查看所有修改过的文件和新文件,您可以使用
PREV_VERSION
是您第一次提交的哈希值。要导出为 zip,您可以使用此代码
注意:
.gitignore
不在export.zip
中To see all modified and new files you can use
PREV_VERSION
is the hash of your first commit.To get an export as zip you can use this code
Note:
.gitignore
is not inexport.zip
您可以使用 --diff-filter 标志来精确执行此操作。
git diff --diff-filter=CMRTUXB master..
应该显示除添加/删除的文件之外的所有内容。You can use the --diff-filter flag to do precisely this.
git diff --diff-filter=CMRTUXB master..
should show everything except added/deleted files.我使用 Notepad++ (Windows) 和这些正则表达式来过滤掉 diff 文件中的扩展类型和某些路径。
唯一的问题是,当它到达终点时。你必须“ctrl+home”并再次进入,直到找不到任何东西。
(用“索引”替换找到的内容)
I've used Notepad++ (Windows), and these regular expressions to filter out extension types and certain paths from a diff file.
Only problem is, when it reaches the end. You have to 'ctrl+home' and go again until it finds nothing.
(Replace whats found with 'Index')