告诉 git 不要在行级别对完全更改的文件进行 diff

发布于 2024-12-17 13:44:16 字数 235 浏览 1 评论 0原文

我在 git 中有一个示例 HTML 文件。最近需要彻底改变,所以关注新旧之间的差异没有太大意义。

目前 diff 将显示为 ++-+--+--+---++,我希望它只显示 --------+++++++。

有没有办法告诉git这个文件更改是一个完整的更改,用户不需要知道行差异,而是整体更改?

PS答案显示了 diff 命令的方式,但是如果我可以在 commit 命令中为特定文件永久指定它,那就太好了。

I have a sample HTML file sitting in git. Recently it needs to be changed completely, so there isn't much point looking at the diff between the new and the old.

Currently the diff will display like ++-+--+--+---++, and I want it to just display --------+++++++.

Is there a way to tell git that this file change is a complete change and users does not need to know line differences, but change as a whole?

P.S. the answer showed the way in diff command, but but it would be great if I can specify permanently this for specific file in commit command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖伴 2024-12-24 13:44:16

git 中的每次提交都会为文件存储一个全新的 blob,即使更改是文本文件中的单个字符更改(稍后它可能只包含 delta 等)

并且您通常不应该担心如何以及什么git 存储(并且磁盘空间很便宜)

更新:

如果您只是担心重写文件时看到的 diff,则可以将 -B 选项与 diff 一起使用:

-B[][/]
--break-rewrites[=[][/]]

将完整的重写更改分解为删除和创建对。这
有两个目的:

它影响相当于完全重写文件的更改方式
不是一系列删除和插入混合在一起
几行碰巧与上下文文本匹配,但作为
一次删除所有旧的内容,然后一次插入
一切都是新的,数字 m 控制 -B 选项的这方面
(默认为 60%)。 -B/70% 指定小于原来的30%
应该保留在结果中,以便 git 将其视为完全重写
(即,否则生成的补丁将是一系列删除和
插入与上下文行混合在一起)。

与 -M 一起使用时,完全重写的文件也被视为
重命名的来源(通常 -M 只考虑消失的文件
作为重命名的来源),数字 n 控制这方面
-B 选项(默认为 50%)。 -B20% 指定更改
添加和删​​除与文件大小的 20% 或更多相比
有资格被选为重命名的可能来源
另一个文件。

还有更复杂的方法,例如使用过滤器分支等来删除(和修改)历史记录,但在这种情况下我不会推荐这些方法。

Every commit in git stores a completely new blob for the file, even if the change was a single character change in a text file ( later on it might be packed with just delta etc. )

And you should generally not be worried about how and what git stores ( and disk space is cheap)

Update:

If you are just worried about the diff that you see when a file is rewritten, you can use the -B option with diff:

-B[<n>][/<m>]
--break-rewrites[=[<n>][/<m>]]

Break complete rewrite changes into pairs of delete and create. This
serves two purposes:

It affects the way a change that amounts to a total rewrite of a file
not as a series of deletion and insertion mixed together with a very
few lines that happen to match textually as the context, but as a
single deletion of everything old followed by a single insertion of
everything new, and the number m controls this aspect of the -B option
(defaults to 60%). -B/70% specifies that less than 30% of the original
should remain in the result for git to consider it a total rewrite
(i.e. otherwise the resulting patch will be a series of deletion and
insertion mixed together with context lines).

When used with -M, a totally-rewritten file is also considered as the
source of a rename (usually -M only considers a file that disappeared
as the source of a rename), and the number n controls this aspect of
the -B option (defaults to 50%). -B20% specifies that a change with
addition and deletion compared to 20% or more of the file’s size are
eligible for being picked up as a possible source of a rename to
another file.

There are more complex methods like using filter-branch etc to remove ( and modify) history, but I won't recommend those in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文