Git merge using recursive strategy and patience option

前端 未结 2 1243
既然无缘
既然无缘 2021-02-05 03:55

How to merge a branch with git using patience option provided by the recursive strategy? I\'m using git version 1.7.3.1.msysgit.0

Even docs are not consistent and, what\

相关标签:
2条回答
  • 2021-02-05 04:29

    I see here the patch introducing the patience option to the recursive merge strategy, base on Git1.7.2.2, but I don't see it in any of the subsequent release notes.

    Yet the patience diff algorithm has been presented since 2009, and is detailed here.

    > grep -i patience *.c
    diff.c: else if (!strcmp(arg, "--patience"))
    diff.c:         DIFF_XDL_SET(options, PATIENCE_DIFF);
    merge-recursive.c:      else if (!strcmp(s, "patience"))
    merge-recursive.c:              o->xdl_opts |= XDF_PATIENCE_DIFF;
    

    The merge command should understand this option... but this function below seems to never be called (not anywhere in merge-recursive.c or in any other *.c file!):

    int parse_merge_opt(struct merge_options *o, const char *s)
    {
        if (!s || !*s)
            return -1;
        if (!strcmp(s, "ours"))
            o->recursive_variant = MERGE_RECURSIVE_OURS;
        else if (!strcmp(s, "theirs"))
            o->recursive_variant = MERGE_RECURSIVE_THEIRS;
        else if (!strcmp(s, "subtree"))
            o->subtree_shift = "";
        else if (!prefixcmp(s, "subtree="))
            o->subtree_shift = s + strlen("subtree=");
        else if (!strcmp(s, "patience"))
            o->xdl_opts |= XDF_PATIENCE_DIFF;
        else if (!strcmp(s, "ignore-space-change"))
            o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
        else if (!strcmp(s, "ignore-all-space"))
            o->xdl_opts |= XDF_IGNORE_WHITESPACE;
        else if (!strcmp(s, "ignore-space-at-eol"))
            o->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;
        else if (!strcmp(s, "renormalize"))
            o->renormalize = 1;
        else if (!strcmp(s, "no-renormalize"))
            o->renormalize = 0;
        else if (!prefixcmp(s, "rename-threshold=")) {
            const char *score = s + strlen("rename-threshold=");
            if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
                return -1;
        }
        else
            return -1;
        return 0;
    }
    

    The "Unknown option" error message is only printed by the handle_options function in git.c.
    And XDF_PATIENCE_DIFF doesn't show anywhere else in git sources (1.7.4)... so yes, I don't know how this could be implemented for the merge.

    0 讨论(0)
  • 2021-02-05 04:37

    The --patience option for git merge-recursive was introduced in commit 58a1ece478c6038a7eb0b6e494d563bd5e6d5978. You can find out in a clone of git.git what versions contain this change with git tag --contains 58a1ece478:

    v1.7.4
    v1.7.4-rc0
    v1.7.4-rc1
    v1.7.4-rc2
    v1.7.4-rc3
    v1.7.4.1
    

    So I suspect that you're just using a slightly too old version of mSysGit. There is a preview version of 1.7.4 available now - I think you should try that one.

    I've just tried this with git version 1.7.4, and the following command line syntax works for me:

    git merge -s recursive -X patience other-branch
    
    0 讨论(0)
提交回复
热议问题