如何将文本合并在一起?就像版本控制系统一样?

发布于 2024-12-15 00:20:53 字数 366 浏览 2 评论 0原文

维基百科说这非常好: http://en.wikipedia.org/wiki /Merge_(revision_control)#Three-way_merge

但是如何实现这一点呢?或者是否有 Ruby on Rails 的 gem/插件可以帮我处理这个问题?

我的情况:
• 我有基础文本
• A 的改变
• B 的变更
• 这两项更改都应包含在内,并且不覆盖其他

我可以指出的任何方向?谢谢!

Wikipedia says this is pretty good: http://en.wikipedia.org/wiki/Merge_(revision_control)#Three-way_merge

But how does one implement that? or are there any gems / plugins for Ruby on Rails that will handle that for me?

My situation:
• I have base text
• changes from person A
• changes from person B
• both changes should be included and not overriding the other

any directions I could be pointed in? thanks!

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

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

发布评论

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

评论(2

情绪 2024-12-22 00:20:53

我认为你应该再次看看 merge3 gem [来源]

这个小例子解释了它:

require 'rubygems'
require 'merge3'

start = <<TEXT
This is the baseline.
The start.
The end.
TEXT
changed_A = <<TEXT
This is the baseline.
The start (changed by A).
The end.
TEXT
changed_B = <<TEXT
This is the baseline.
The start.
B added this line.
The end.
TEXT

result = Merge3::three_way(start, changed_A, changed_B)

puts result

它生成的输出是:

This is the baseline.
The start (changed by A).
B added this line.
The end.

我不确定它如何处理合并冲突,并且由于它应该处理文件的 3 路合并,因此它似乎是基于行的。如果这是一个问题(因为您的示例尝试比较简单的字符串),您可以在每个字符之间添加换行符。

希望这有帮助。

I think you should look at the merge3 gem again [source].

This small example explains it:

require 'rubygems'
require 'merge3'

start = <<TEXT
This is the baseline.
The start.
The end.
TEXT
changed_A = <<TEXT
This is the baseline.
The start (changed by A).
The end.
TEXT
changed_B = <<TEXT
This is the baseline.
The start.
B added this line.
The end.
TEXT

result = Merge3::three_way(start, changed_A, changed_B)

puts result

The output it generates is:

This is the baseline.
The start (changed by A).
B added this line.
The end.

I am not sure how it handles merge conflicts, and since it is supposed to handle 3-way merges of files, it seems to be line-based. If that is a problem (as your example tries to compare simple string), you could add a newline between every character.

Hope this helps.

也只是曾经 2024-12-22 00:20:53

如果您正在存储希望能够合并的版本化文本,那么听起来您有一个调用版本控制系统的完美用例。将文本存储在文件中并调用 VCS 进行版本控制操作(也许 Git 或 Grit gems 会有所帮助)。

If you're storing versioned text that you want to be able to merge, then it sounds like you have a perfect use case for calling a version control system. Store the text in files and call the VCS for version control operations (perhaps the Git or Grit gems would be helpful).

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