当你创建一个合并时,你可以选择说明如何处理合并。通常的策略是递归。这意味着 Git 将遍历每个目录(树)并找出哪些文件与基本修订版本相比有差异,然后使用有变化的文件。(如果两者都有变化,新文件的内容将被在文本上合并,如果这有问题,就会发生冲突。)这就是为什么在执行操作后会看到消息 “Merge made by recursive” 的原因:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(master) $ git checkout Alex Switched to branch 'Alex' (Alex) $ git merge Bob Merge made by recursive. BobsFile | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 BobsFile (Alex) $ git log --oneline --graph * d612aab Merge branch 'Bob' into Alex |\ | * 8afb2d3 Bob's File * | 4abf59e Alex's File |/ * 5cba624 Hello (Alex) $ git show d612aa commit d612aab9858289ed027230d3b9a7b2a7a5e75945 Merge: 4abf59e 8afb2d3 … Merge branch 'Bob' into Alex
(master) $ git checkout Alex Switched to branch 'Alex' (Alex) $ echo Hello, my name is Alex > Hello (Alex) $ git commit -a -m "My name is Alex" [Alex c2cb955] My name is Alex 1 files changed, 1 insertions(+), 1 deletions(-) (Alex) $ git checkout Bob Switched to branch 'Bob' (Bob) $ echo Hello, my name is Bob > Hello (Bob) $ git commit -a -m "My name is Bob" [Bob 7cb6225] My name is Bob 1 files changed, 1 insertions(+), 1 deletions(-) (Bob) $ git checkout master (master) $ git merge Alex Bob Trying simple merge with Alex Trying simple merge with Bob Simple merge did not work, trying automatic merge. Auto-merging Hello ERROR: content conflict in Hello fatal: merge program failed Automatic merge failed; fix conflicts and then commit the result. (master|MERGING) $ git ls-files --stage 100644 ada4c4c4f33cd190fe40769d5ca9826adb9fb7ce 0 AlexsFile 100644 eea826732acee08a8cf83445e3b98cf58f11ce5c 0 BobsFile 100644 ca4eef2f4e3f1fe92028176cb547b590a08c2259 1 Hello 100644 a5a820416bae2c7b77340e5b2120aab9595d2bfc 2 Hello 100644 98b16693fe64acb9d002af1fe5f5162d58bd40b4 3 Hello 100644 09d774502f97ba9a46f25f8f11601b653c376828 0 NewFile (master|MERGING) $
(master) $ echo Hello World > Hello (master) $ git commit -a -m "Hello World" [master fe79e59] Hello World 1 files changed, 1 insertions(+), 1 deletions(-) (master) $ git merge Alex Bob Trying simple merge with Alex Simple merge did not work, trying automatic merge. Auto-merging Hello ERROR: content conflict in Hello fatal: merge program failed Automated merge did not work. Should not be doing an Octopus. Merge with strategy octopus failed.
ours
ours strategy可以验证它们是相同的,因为由 HEAD 指向的树与由 HEAD^1(即父节点)指向的树相同。后缀^{tree}用于显示与提交相关联的树。