How to list stats of resolved conflicts in a merge commit?

前端 未结 1 1025
粉色の甜心
粉色の甜心 2021-01-25 01:09

In merging a branch, a conflict may happen which we should resolve to complete the merge. How can we list ONLY the stats of resolved conflicts in merge?

相关标签:
1条回答
  • 2021-01-25 01:26

    TL;DR answer: Just try.

    Branches have a zero cost in git so just create a couple of test_merge_source and test_merge_destination branches and start the merge. After 5-10 minutes you are either done or you still have a little/some/much left because a few/some/many conflicts occurred and you can choose to finish/discard the merge attempt.


    I am sorry to provide you with a negative answer, but the premise for your question is fundamentally flawed and what you ask for is impossible.

    Because it is impossible for any computer algorithm to determine if something is a conflict or not. Yes there are tools that will automate merging of different files, but even a perfect and trouble free merge might still constitute a conflict.

    The question is in the same span as asking for how many lines that are changed between versions, which is an equally impossible question to answer.

     /* example1.c */
     #include <stdio.h>
    -#include <varargs.h>
    +#include <stdarg.h>
     ...
     /* In this diff one line is changed */
    
    
     /* example2.c */
     #include <stdio.h>
    -#include <varargs.h>
    +#include <math.h>
     ...
    /* In this diff one line is removed and one line added */
    

    As shown above, if a line is changed or not is entirely context dependent. Therefore no (sane) version control tool will ever try to tell you how many lines have changed, they only say lines added/removed.


    Now, you might say that you are interested in failed automatic merges and actually not conflicts. Fair enough, but this is then wholly dependent on the tool used. Git's internal merge handling will for instance fail if two lines next to each other are modified while KDiff3 will not (which is usually what you want but there is a higher risk of this being incorrect than for lines further apart, so there is a trade off).

    This means that what gets automatically merged is not a static thing and can change over time. So are you looking for what was not automatically merged with the git version used when the code was originally merged or what will be the result for a new merge with today's git?1

    There is a git command rerere which will record resolved failed merge attempts, which perhaps might be used to extract such information. But it has to be explicitly enabled, it significantly changes the merge handling, it is only a per repository setting, it only keeps history for a limited time and it might be cleared, so it is far from a drop in solution.


    1 The answer to that question is actually just try, as pointed out in the beginning.

    0 讨论(0)
提交回复
热议问题