如何检测裸 git 存储库中分支之间的冲突
How to detect conflicts between branches in the bare git repository
目前我需要在服务器端的裸仓库中找到分支之间的冲突(git 无法自动解决)。
我正在尝试使用 git read-tree -i -m ${merge_base} ${branch_a} ${branch_b}
生成索引文件,然后通过 git ls-files --stage
读取其内容。但是仅仅通过stage number来判断文件的冲突还是不够的,因为即使两个分支都修改了文件的同一行,git仍然可以自动解决冲突,如果修改是准确的相同。
如果有人知道如何解决这个问题,或者知道如何使用 git 管道命令进行 merge
操作,请告诉我。
感谢您的帮助!
我会检查 git 合并其他分支 --no-ff --no-commit。然后你会看到会发生什么,如果你遇到大混乱,你可以恢复。
我不会使用管道命令。如果这很重要,请看一下
合并的作用。
尝试git merge-tree
。
这里有一个 bash 函数的示例,它采用两个分支作为参数。如果有任何冲突,它输出 "conflict",否则输出 "no conflict"。该功能不够强大。
function testconflict() {
foo=
bar=
mergebase=$(git merge-base $foo $bar)
if [ "$mergebase" = "" ];then
#in case foo and bar have no common ancestor, use the empty tree as the merge base
mergebase=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
#test if the output has conflict markers of "merge" style
git merge-tree $mergebase $foo $bar | xargs |
if grep -oe '<<<<<<<.*=======.*>>>>>>>';then
echo conflict
else
echo no conflict
fi
}
目前我需要在服务器端的裸仓库中找到分支之间的冲突(git 无法自动解决)。
我正在尝试使用 git read-tree -i -m ${merge_base} ${branch_a} ${branch_b}
生成索引文件,然后通过 git ls-files --stage
读取其内容。但是仅仅通过stage number来判断文件的冲突还是不够的,因为即使两个分支都修改了文件的同一行,git仍然可以自动解决冲突,如果修改是准确的相同。
如果有人知道如何解决这个问题,或者知道如何使用 git 管道命令进行 merge
操作,请告诉我。
感谢您的帮助!
我会检查 git 合并其他分支 --no-ff --no-commit。然后你会看到会发生什么,如果你遇到大混乱,你可以恢复。 我不会使用管道命令。如果这很重要,请看一下 合并的作用。
尝试git merge-tree
。
这里有一个 bash 函数的示例,它采用两个分支作为参数。如果有任何冲突,它输出 "conflict",否则输出 "no conflict"。该功能不够强大。
function testconflict() {
foo=
bar=
mergebase=$(git merge-base $foo $bar)
if [ "$mergebase" = "" ];then
#in case foo and bar have no common ancestor, use the empty tree as the merge base
mergebase=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
#test if the output has conflict markers of "merge" style
git merge-tree $mergebase $foo $bar | xargs |
if grep -oe '<<<<<<<.*=======.*>>>>>>>';then
echo conflict
else
echo no conflict
fi
}