告诉 git 不要在行级别对完全更改的文件进行 diff
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
git 中的每次提交都会为文件存储一个全新的 blob,即使更改是文本文件中的单个字符更改(稍后它可能只包含 delta 等)
并且您通常不应该担心如何以及什么git 存储(并且磁盘空间很便宜)
更新:
如果您只是担心重写文件时看到的 diff,则可以将 -B 选项与 diff 一起使用:
还有更复杂的方法,例如使用过滤器分支等来删除(和修改)历史记录,但在这种情况下我不会推荐这些方法。
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:
There are more complex methods like using filter-branch etc to remove ( and modify) history, but I won't recommend those in this case.