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

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

问题描述

这是多年来多次提出的问题。我找到了很多答案,特别是这一个:



这个页面包含了一个详细的指南,介绍如何设置一个总是返回失败的合并驱动程序,从而实现手动合并。我已经尝试过为Windows调整该解决方案:


  1. 我将以下内容添加到我的%homepath% \.gitconfig



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


  2. 我将驱动程序更改为

    cmd / Kecho工作> merge.log& git合并文件%1%%2 %% 3%& exit 1



    echo工作> merge.log 被添加以检查驱动程序是否被调用)。

  3. ,并且在repo的根目录下创建了一个文件。 gitattributes 与以下行:



    *。txt merge = verify


不幸的是,它不起作用。我试图合并文件 feature.txt ,并且,唉,合并成功完成。看起来这个驱动程序根本没有被调用,因为merge.log文件没有被创建。



我做错了什么吗?任何解决强迫手动合并问题的解决方案都是非常受欢迎的。

解决方案

tl; dr:它似乎工作。与您的版本相比,有2个变化,但没有它们,我也合并失败(因为驱动程序基本上未能运行)。



我试过这个:



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

  exit 1 

为合并类型创建一个部分



  [mergeerrorout] 
name = errorout
driver =〜/ bin / errorout.bat%A %O%B

创建.gitattributes文件:

  *。txt merge = errorout 

,错误报告,因为我认为你想要它被报告:

  $ git merge a 

C:\ ...> exit 1
自动合并f.txt
CONFLICT(内容):合并f.txt中的冲突
自动合并失败;修复冲突,然后提交结果。

我有git版本2.11.0.rc1.windows.1。我无法按照指定的顺序运行复杂的命令,它报告了一些语法错误。


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

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

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. I added the following to my %homepath%\.gitconfig:

    [merge "verify"] name = merge and verify driver driver = %homepath%\\merge-and-verify-driver.bat %A %O %B

  2. I changed the driver to

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

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

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

    *.txt merge=verify

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: 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)

I have tried this:

Create a merge driver $HOME/bin/errorout.bat:

exit 1

Create a section for the merge type

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

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.

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天全站免登陆