How to realize a diff function?

后端 未结 5 2028
耶瑟儿~
耶瑟儿~ 2021-02-04 22:49

How can I implement a diff function, such as Stack Overflow\'s question revision history?

5条回答
  •  日久生厌
    2021-02-04 23:26

    If what you want is revision history, don't reinvent the wheel starting at diff. Just throw everything into version control and use its diff and logging facilities. For simple, linear history something as simple as RCS will do. Or you can throw the latest cannon at it and use git.

    Most diff utilities do a line-by-line diff. Stack overflow does a word-by-word diff. For that something like wdiff is necessary. Most version control systems let you plug in the diff utility. Out of the box, git diff --color-words comes remarkably close to what is done here. With a little fiddling with the settings you can probably get it to spit out something you can then make into a pretty web page.

提交回复
热议问题