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?
-
What do you mean by 'How can we list ONLY the stats of resolved conflicts in merge' ? Please explain. – Kaushal Kumar Jul 18 '16 at 13:43
-
Suppose you start with branch X, made a new branch called Y from branch X and added two commits to it called C1 and C2. Now if you merge branch Y back into branch X (with NO conflict) and look at the stats of changes in merge commit, you see the stats of changes you made in commits C1 and C2. But if you encounter a conflict in your merging process and you successfully resolve it, at the end the stats of merge commit contains the changes in commit C1, C2 and commit you made to resolve the conflict. In later case I want to know if there is the way to see ONLY the stats of conflict commit. – mxamin Jul 18 '16 at 17:34
-
If you do `git pull origin Y` it will make only one commit( conflict commit). If you do `git pull --no-ff origin Y` it will merge with all the commits including conflict commit. – Kaushal Kumar Jul 18 '16 at 17:51
-
Ok, but I'm not going to merge the branch, it was merged before. I want to know its conflict commit stat. – mxamin Jul 19 '16 at 05:13
-
`git diff --name-only --diff-filter=U` – Kaushal Kumar Jul 19 '16 at 05:33
-
Possible duplicate of [What's the simplest way to git a list of conflicted files?](http://stackoverflow.com/questions/3065650/whats-the-simplest-way-to-git-a-list-of-conflicted-files) – Kaushal Kumar Jul 19 '16 at 05:37
1 Answers
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.

- 26,565
- 10
- 94
- 165