如果你不介意使用图形应用程序,我真的可以推荐KDiff3,它是一个很棒的合并工具。在你的情况下,运行
kdiff3 -o output.txt m1 m2
你会得到
对于每个合并冲突,按 A 或 B 按钮选择要选择的行(或两者)。您可以在底部区域随意编辑。
更新:如果您只想在终端中以文本模式工作,那么设置一个临时 git 存储库非常便宜。学习使用 git 需要一些努力,但它是可行的。对于您的情况,以下命令可以完成工作:
$ mkdir /tmp/test
$ cd /tmp/test
$ git init
Initialized empty Git repository in /tmp/test/.git/
$ touch gitfile
$ git add gitfile
$ git commit -m "initial commit"
[master (root-commit) 31efd12] initial commit
0 files changed
create mode 100644 gitfile
$ git checkout -b m1-branch
Switched to a new branch 'm1-branch'
$ cat m1 >> gitfile
$ git add gitfile
$ git commit -m "m1 content"
[m1-branch 420b423] m1 content
1 file changed, 3 insertions(+)
$ git checkout -b m2-branch master
Switched to a new branch 'm2-branch'
$ cat m2 >> gitfile
$ git add gitfile
$ git commit -m "m2 content"
[m2-branch c4c525a] m2 content
1 file changed, 3 insertions(+)
$ git checkout master
Switched to branch 'master'
$ git merge m1-branch m2-branch
Fast-forwarding to: m1-branch
Trying simple merge with m2-branch
Simple merge did not work, trying automatic merge.
Auto-merging gitfile
ERROR: content conflict in gitfile
fatal: merge program failed
Automatic merge failed; fix conflicts and then commit the result.
$ cat gitfile
hello there
<<<<<<< .merge_file_qRmZJF
my friend
=======
my chum
>>>>>>> .merge_file_BUlXHH
how are you
$