如何让 diff 停止破坏函数文档块?

发布于 2024-12-04 01:49:11 字数 254 浏览 1 评论 0原文

如果我在代码中添加一个函数,我的 diff 看起来像这样:

 }

 /**
+ * My new function docblock.
+ */
+function my_function($foo) { }
+
+/**
  * The next function's docblock.
  *

有没有办法阻止 diff 破坏这个?

我尝试了 git 的 --patience 标志,但产生了相同的结果。

If I add a function to my code, my diff looks like this:

 }

 /**
+ * My new function docblock.
+ */
+function my_function($foo) { }
+
+/**
  * The next function's docblock.
  *

Is there a way to stop diff from mangling this?

I tried git's --patience flag but that produces the same result.

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

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

发布评论

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

评论(2

没企图 2024-12-11 01:49:11

如果您期望的是一个更好的差异,它可以“理解”注释块比较中的存在,并且以不分割这些块的方式对齐差异,那么您当前就已经关闭了。

“diff”的内部算法自动将块与差异仍然为“true”的最大数字的行对齐。例如,而不是

 }

+/**
+ * My new function docblock.
+ */
+function my_function($foo) { }
+
 /**
  * The next function's docblock.
  *

Diff 将始终返回您在问题中描述的结果。许多基于 GNU diff 的工具都遇到这个问题。

If what you expect would a better diff which would "understand" the presence in the comparison of a comment block and have the diff aligned in a way which does not split those blocks, you are off currently.

The internal algorithm of "diff" automatically aligns the block to the line with the greatest number for which the difference is still 'true'. For example rather than

 }

+/**
+ * My new function docblock.
+ */
+function my_function($foo) { }
+
 /**
  * The next function's docblock.
  *

Diff will always return the result that you described in your question. Many tools which are based on GNU diff suffer from this problem.

许一世地老天荒 2024-12-11 01:49:11

您想要的是一个比较程序结构的工具,而不是“文本行”。

请参阅我们的 SmartDifferencer 工具,该工具使用编程语言的结构作为其比较程序的源文本。指导。有一个适用于多种语言(C++、C#、Java、COBOL...)的 SmartDifferencer

对于 OP 的示例,它应该简单地指出该函数(及其文档块)已被添加。

What you want is a tool that compares program structures, not "lines of text".

See our SmartDifferencer tools that compare the source text of programs, using the structure of the programming language as its guide. There's a SmartDifferencer for many languages (C++, C#, Java, COBOL, ...)

For OP's example, it should simply note that the function (and its docblock) have been added.

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