如何让 diff 停止破坏函数文档块?
如果我在代码中添加一个函数,我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您期望的是一个更好的差异,它可以“理解”注释块比较中的存在,并且以不分割这些块的方式对齐差异,那么您当前就已经关闭了。
“diff”的内部算法自动将块与差异仍然为“true”的最大数字的行对齐。例如,而不是
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
Diff will always return the result that you described in your question. Many tools which are based on GNU diff suffer from this problem.
您想要的是一个比较程序结构的工具,而不是“文本行”。
请参阅我们的 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.