3

マージする必要がある 2 つのローカル ファイルがあります。どちらも git でバージョン管理されていません。ファイルをマージするための Linux コマンドはありますか? を試しmergeましたが、有用な出力が得られませんでした。mergefile は、最初のファイル全体が削除され、2 番目のファイルが出力全体であることを示しているようです。

$ cat m1
hello there
my friend
how are you
$
$ cat m2
hello there
my chum
how are you
$
$ merge merge m1 m2
$ cat merge
<<<<<<< merge
=======
hello there
my chum
how are you
>>>>>>> m2

編集

明確にするために、2つのファイルを端から端まで単に接着するのではなく、インラインでファイル間の違いを示すgitスタイルのマージファイルを作成しようとしています(コードでは機能しません)。

4

1 に答える 1

4

グラフィカル アプリケーションの使用を気にしないのであれば、素晴らしいマージ ツールであるKDiff3を強くお勧めします。あなたの場合、実行します

kdiff3 -o output.txt m1 m2

そしてあなたは得るでしょう

kdiff3 スクリーンショット

マージ競合ごとに、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
$
于 2012-09-20T20:57:10.283 に答える