Ответ 1
Предположим, что A является строгим, прямым дочерним элементом текущей ветки. Тогда предположим, что B - строгий, прямой ребенок из A.
Слияние octopus, которое обрабатывает главы, заданные как аргументы слева направо, поэтапно относительно дерева, но независимо от индекс успешно работает без конфликта, если он пытается применить B, а затем A, но сталкивается с конфликтом, если он выполняет преобразование.
Согласно руководству git-merge
, раздел СТРАТЕГИИ СЛИШКОМ:
octopus
This resolves cases with more than two heads, but refuses to do a
complex merge that needs manual resolution.
Например:
~ $ git init testdir && cd testdir && echo "This is C" > myfile
Initialized empty Git repository in /home/huitseeker/testdir/.git/
~/testdir $ git add myfile && git commit -m "C"
[master (root-commit) f0c8c82] C
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 myfile
~/testdir(master) $ git checkout -b "A" && echo "This is A1" > myfile
Switched to a new branch 'A'
~/testdir(A) $ git commit -m "A1" myfile
[A ac5b51c] A1
1 files changed, 1 insertions(+), 1 deletions(-)
~/testdir(A) $ git checkout -b "B" && echo "This is B1" >> myfile
Switched to a new branch 'B'
~/testdir(B) $ git commit -m "B1" myfile
[B 5bc838c] B1
1 files changed, 1 insertions(+), 0 deletions(-)
~/testdir(B) $ git checkout master
Switched to branch 'master'
~/testdir(master) $ git merge B A
Fast-forwarding to: B
Already up-to-date with A
Merge made by octopus.
myfile | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
~/testdir(master) $ git reset --hard HEAD^^^
HEAD is now at f0c8c82 C
~/testdir(master) $ git merge A B
Fast-forwarding to: A
Fast-forwarding to: B
error: Entry 'myfile' would be overwritten by merge. Cannot merge.
Merge with strategy octopus failed.
~/testdir(master) $ cat myfile
This is A1
В самом деле, при быстрой пересылке на A метка мастера не продвигается вперед, хотя дерево имеет.
~/testdir(master) $ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: myfile
#
Если, глядя на код того, что делает слияние осьминога, я выполняю это вручную (смотрите выше для хэшей):
~/testdir(master) $ git reset --hard f0c8c82
HEAD is now at f0c8c82 C
~/testdir(master) $ git read-tree -u -m f0c8c82 ac5b51c
~/testdir(master) $ git read-tree -u -m f0c8c82 5bc838c
error: Entry 'myfile' would be overwritten by merge. Cannot merge.
В другом направлении (merge B A
) теперь, если вы снова посмотрите на код слияния-осьминога, он пытается обнаружить ветвь, которую мы пытаемся добавить, уже находится в дереве (второй case
for
). Действительно, при слиянии A он видит, что ac5b51c (a.k.a. A head) является общим предком A и B и прерывается без второго read-tree
.
Это соответствует новой версии git: хотя я указал на v.1.3.1, это все еще происходит с моей версией.
~/testdir(master) $ git --version
git version 1.7.5.4
tl; dr: вы хотите, чтобы ваши ветки слияния осьминогов касались отдельных файлов