Git - 即使没有冲突,如何强制手动合并 [英] Git - how to force manual merge even if there is no conflict

查看:25
本文介绍了Git - 即使没有冲突,如何强制手动合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个多年来被问过很多次的问题.我找到了很多答案,尤其是这个:

This is a question which was asked many times over the years. I have found a number of answers, in particular this one:

Git - 如何强制合并冲突并手动合并所选文件 (@Dan Moulding)

Git - how to force merge conflict and manual merge on selected file (@Dan Moulding)

此页面包含如何设置合并驱动程序的详细指南,该驱动程序总是返回失败,从而使手动合并成为可能.我试图为 Windows 调整该解决方案:

This page contains is a detailed guide how to set up a merge driver that would always return failure and thus make possible a manual merge. I have tried to adapt that solution for Windows:

  1. 我在 %homepath%.gitconfig 中添加了以下内容:

[合并验证"]名称 = 合并并验证驱动程序驱动程序 = %homepath%\merge-and-verify-driver.bat %A %O %B

我把驱动改成了

cmd/K "echo Working > merge.log & git merge-file %1% %2% %3% & exit 1"

(添加了echo Working > merge.log 来检查驱动是否被调用).

(echo Working > merge.log was added to check whether the driver was invoked).

并且,在 repo 的根目录下,创建了一个文件 .gitattributes,其中包含以下行:

and, at the root of the repo, created a file .gitattributes with the following line:

*.txt merge=verify

不幸的是,它不起作用.我试图合并一个文件,feature.txt,但是,合并成功完成.似乎根本没有调用驱动程序,因为没有创建 merge.log 文件.

Unfortunately, it does not work. I tried to merge a file, feature.txt, and, alas, the merge completed successfully. It seems that the driver was not invoked at all, since the merge.log file was not created.

我做错了什么吗?任何强制手动合并问题的解决方案都是最受欢迎的.

Do I do anything wrong? Any solution to the problem of forcing manual merge is most welcome.

推荐答案

tl;dr:我试着重复你描述的内容,它似乎有效.与您的版本相比,有 2 个更改,但没有它们,我的合并也失败了(因为驱动程序基本上无法运行)

tl;dr: I tried to repeat what you described and it seems to work. There were 2 changes compared to yours version but without them I have merge failed as well (because driver basically failed to run)

我已经试过了:

创建一个合并驱动$HOME/bin/errorout.bat:

exit 1

为合并类型创建一个部分

Create a section for the merge type

[merge "errorout"]
   name = errorout
   driver = ~/bin/errorout.bat %A %O %B

创建 .gitattributes 文件:

Create the .gitattributes file:

*.txt merge=errorout

之后,错误被报告,因为我认为你希望它被报告:

After that, error is reported as I think you want it to be reported:

 $ git merge a

 C:...>exit 1
 Auto-merging f.txt
 CONFLICT (content): Merge conflict in f.txt
 Automatic merge failed; fix conflicts and then commit the result.

我有 git 版本 2.11.0.rc1.windows.1.我无法使您指定的复杂命令成功运行,它报告了一些语法错误.

I have git version 2.11.0.rc1.windows.1. I was not able to make the complicated command as you specified run successfully, it was reporting some syntax errors.

这篇关于Git - 即使没有冲突,如何强制手动合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆