在两个单独的文件上运行git合并算法 [英] run git merge algorithm on two individual files

查看:169
本文介绍了在两个单独的文件上运行git合并算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在git仓库中的两个任意文件上利用git-merge算法。这是我的工作目录:

I want to take advantage of the git-merge algorithm on two arbitrary files in a git repo. Here is my working directory:

folder/
    file1
    file2

file1和file2是类似的,但我想看看git如何合并它们,就好像它们是同一个文件的不同版本一样。换句话说,我想要这样的东西:

file1 and file2 are similar, but I want to see how git would merge them as if they were different versions of the same file. In other words, I want something like this:

git merge-files file1 file2 > merge_of_file1_file2

有没有办法做到这一点?

Is there a way to do this?

推荐答案

这没有意义,因为你没有提供共同的祖先。然而,如果你确实有一个,你可以使用:

This doesn't really make sense, because you're not providing a common ancestor. If you do have one, however, you can use:

git merge-file <current-version> <common-ancestor> <other-version>

这会将结果放入当前版本文件中;如果你想在其他地方使用,请使用:

This places the results in the current version file; if you want them elsewhere, use:

git merge-file -p <current> <common> <other> > <dest>

它需要共同的祖先来提供一些相关变化。你可以通过提供一个空文件或者从你的版本库的历史记录中提供一个旧版本的副本,但是结果的质量取决于你选择一个共同祖先的程度,因为它合并了两个差异,在这和每个新版本之间。如果两个文件非常相似(很多文件至少有三条相同的文件),一个空文件只能工作。

It needs the common ancestor to provide something to consider changes relative to. You could hack it, by providing an empty file or a copy of an older version of one of them from the history of your repository, but the quality of results will depend on how well you select a common ancestor, since it's merging the two diffs, between that and each of the new versions. An empty file will only work well if the two are very similar (many runs of at least three identical lines).

如果没有这个,所有你真的可以看看差异:

Without that, all you can really do is look at the differences:

git diff --no-index file1 file2

这篇关于在两个单独的文件上运行git合并算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆