简体   繁体   English

Git合并 - 符号链接冲突

[英]Git merge - symlink conflict

After merging I got a symbolic links conflict:合并后,我遇到了符号链接冲突:

$ git status
[SKIP]
both added:      file.txt
[SKIP]

Git diff doesn't show the target values: Git diff 不显示目标值:

$ git diff
[SKIP]
diff --cc file.txt
index 5873c9d,e31df9a..0000000
--- a/file.txt
+++ b/file.txt

Is there a simple way to compare symbolic link target values?有没有一种简单的方法来比较符号链接目标值?

Using git show, you could display the target for that link.使用 git show,您可以显示该链接的目标。
I just tested it on a test repo, with a link referencing the file one or the file two in different branches.我刚刚在测试仓库上对其进行了测试,其中有一个链接引用了不同分支中的文件一或文件二。
The merge has a conflict:合并有冲突:

vonc@voncavn7:/mnt/d/git/tests/sml/a$ git commit -m "add link from one"
[one 22b4906] add link from one
 1 file changed, 1 insertion(+)
 create mode 120000 link
vonc@voncavn7:/mnt/d/git/tests/sml/a$ git merge -s recursive two
Auto-merging link
CONFLICT (add/add): Merge conflict in link
Automatic merge failed; fix conflicts and then commit the result.
vonc@voncavn7:/mnt/d/git/tests/sml/a$ git diff
diff --cc link
index 43dd47e,1ed3c7a..0000000
--- a/link
+++ b/link

But I can see which one points to which:但我可以看出哪一个指向哪一个:

vonc@voncavn7:/mnt/d/git/tests/sml/a$ git show :2:link
one
vonc@voncavn7:/mnt/d/git/tests/sml/a$ git show :3:link
zero

Note that with Git 2.16.x/2.17, you would be able to resolve it automatically, should you chose a merge option .请注意,使用 Git 2.16.x/2.17,如果您选择合并选项,您将能够自动解决它。
That is because " git merge -Xours/-Xtheirs " learned to use our/their version when resolving a conflicting updates to a symbolic link.那是因为“ git merge -Xours/-Xtheirs ”在解决符号链接的冲突更新时学会了使用我们/他们的版本。

See commit fd48b46 (26 Sep 2017) by Junio C Hamano ( gitster ) .请参阅Junio C gitster ( gitster ) 的提交 fd48b46 (2017 年 9 月 26 日
(Merged by Junio C Hamano -- gitster -- in commit 14b9d9a , 23 Jan 2018) (由Junio C gitster合并-- gitster -- in commit 14b9d9a ,2018 年 1 月 23 日)

The -Xours / -Xtheirs merge options were originally defined as a way to "force" the resolution of 3way textual merge conflicts to take one side without using your editor, hence did not even trigger in situations where you would normally not get the <<< === >>> conflict markers. -Xours / -Xtheirs合并选项最初被定义为一种在不使用编辑器的情况下“强制”解决 3way 文本合并冲突的方法,因此甚至不会在您通常无法获得<<< === >>>冲突标记。

This was improved for binary files back in 2012 with a944af1 ("merge: teach -Xours / -Xtheirs to binary ll-merge driver", 2012-09-08, Git v1.7.12.4).这在 2012 年用a944af1改进了二进制文件(“merge:teach -Xours / -Xtheirs to binary ll-merge driver”,2012-09-08,Git v1.7.12.4)。

Teach a similar trick to the codepath that deals with merging two conflicting changes to symbolic links.教一个类似的技巧来处理将两个冲突的更改合并到符号链接的代码路径。


Note that with Git 2.24 (Q4 2019), a bug in merge-recursive code that triggers when a branch with a symbolic link is merged with a branch that replaces it with a directory has been fixed.请注意,在 Git 2.24(2019 年第四季度)中,当具有符号链接的分支与用目录替换它的分支合并时触发的合并递归代码中的错误已得到修复。

See commit 83e3ad3 (18 Sep 2019) by Jonathan Tan ( jhowtan ) .请参阅Jonathan Tan ( jhowtan ) 的commit 83e3ad3 (2019 年 9 月 18 日
Helped-by: Elijah Newren ( newren ) .帮助者:以利亚纽伦( newren
(Merged by Junio C Hamano -- gitster -- in commit 1f4485b , 07 Oct 2019) (由Junio C gitster合并gitster 提交 1f4485b ,2019 年 10 月 7 日)

When the working tree has:当工作树有:

 - bar (directory) - bar/file (file) - foo (symlink to .)

(note that lstat() for " foo/bar " would tell us that it is a directory) (注意“ foo/bar ”的lstat()会告诉我们它是一个目录)

and the user merges a commit that deletes the foo symlink and instead contains:并且用户合并一个删除 foo 符号链接的提交,而是包含:

 - bar (directory, as above) - bar/file (file, as above) - foo (directory) - foo/bar (file)

the merge should happen without requiring user intervention.合并应该在不需要用户干预的情况下发生。
However, this does not happen.然而,这不会发生。

This is because dir_in_way() , when checking the working tree, thinks that " foo/bar " is a directory.这是因为dir_in_way()在检查工作树时认为“ foo/bar ”是一个目录。
But a symlink should be treated much the same as a file: since dir_in_way() is only checking to see if there is a directory in the way, we don't want symlinks in leading paths to sometimes cause dir_in_way() to return true.但是符号链接应该和文件一样对待:因为dir_in_way()只是检查路径中是否有目录,我们不希望引导路径中的符号链接有时会导致dir_in_way()返回 true。

Teach dir_in_way() to also check for symlinks in leading paths before reporting whether a directory is in the way.dir_in_way()在报告目录是否妨碍之前还检查前导路径中的符号链接。


With Git 2.33 (Q3 2021), the "union" conflict resolution variant misbehaved when used with binary merge driver.在 Git 2.33(2021 年第三季度)中,“联合”冲突解决变体在与二进制合并驱动程序一起使用时行为异常。

See commit 382b601 , commit 7f53f78 , commit 7d879ad (10 Jun 2021) by Jeff King ( peff ) .请参阅Jeff King ( peff ) 的commit 382b601commit 7f53f78commit 7d879ad (2021 年 6 月 10 日
(Merged by Junio C Hamano -- gitster -- in commit 308528a , 13 Jul 2021) (由Junio C gitster合并-- gitster -- in commit 308528a ,2021 年 7 月 13 日)

ll_binary_merge() : handle XDL_MERGE_FAVOR_UNION ll_binary_merge() : 处理XDL_MERGE_FAVOR_UNION

Signed-off-by: Jeff King签字人:Jeff King

Prior to commit a944af1 (" merge : teach -Xours/-Xtheirs to binary ll-merge driver", 2012-09-08, Git v1.8.0-rc0 -- merge listed in batch #7 ), we always reported a conflict from ll_binary_merge() by returning "1" (in the xdl_merge and ll_merge code, this value is the number of conflict hunks).提交 a944af1之前(“ merge :将 -Xours/-Xtheirs 教授到二进制 ll-merge 驱动程序”,2012 年9 月 8 日,Git v1.8.0-rc0 -- 批处理 #7 中列出的合并),我们总是报告来自ll_binary_merge()通过返回“1”(在xdl_mergell_merge代码中,该值是冲突的数量)。
After that commit, we report zero conflicts if the "variant" flag is set, under the assumption that it is one of XDL_MERGE_FAVOR_OURS or XDL_MERGE_FAVOR_THEIRS .在提交之后,如果设置了“variant”标志,我们报告零冲突,假设它是XDL_MERGE_FAVOR_OURSXDL_MERGE_FAVOR_THEIRS

But this gets confused by XDL_MERGE_FAVOR_UNION .但这会被XDL_MERGE_FAVOR_UNION混淆。
We do not know how to do a binary union merge, but erroneously report no conflicts anyway (and just blindly use the "ours" content as the result).我们不知道如何进行二元联合合并,但无论如何都会错误地报告没有冲突(并且只是盲目地使用“我们的”内容作为结果)。

Let's tighten our check to just the cases that a944af1 meant to cover.让我们只检查a944af1打算涵盖的情况。
This fixes the union case (which existed already back when that commit was made), as well as future-proofing us against any other variants that get added later.这修复了联合案例(在进行提交时已经存在),并为我们提供了针对以后添加的任何其他变体的未来证明。

Note that you can't trigger this from " git merge-file --union " ( man ) , as that bails on binary files before even calling into the ll-merge machinery.请注意,您不能从“ git merge-file --union( man )触发此操作,因为它甚至在调用 ll-merge 机器之前都会对二进制文件进行git merge-file --union

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM