Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm merging branch "feature_1" into current branch "master".
After executing: "git merge feature_1" command I'm getting several unmerged paths, those are conflicts that needed to be resolved manually.
I would like to write a python script that will go over the unmerged paths and extract the specific lines that caused the conflict and the Authors of those lines on both branches "feature_1" and "master".

Thanks.

What I have tried:

So far i tried to run diff function in Git object.
Posted
Updated 25-Jun-18 23:21pm

$ git mergetool
Is your friend.
 
Share this answer
 
Comments
columbos14927 26-Jun-18 2:38am    
Hi,
After git merge i have a group of unmerged files.
If i run this command: git diff --name-only --diff-filter=U
I get a list of files that need to be merged manually.
What i want to do for every file in the above list is to get the line number of every conflict without to run the git mergetool since i want to do it with a script automatically.

Thanks
There is no such thing as "automatic merge". A merge conflict happens when two humans have made "incompatible" changes. A human must manually decide what changes to keep. The command to run is: git mergetool
This will bring up an editor highlighting the conflicts.

I also recommend setting up a gui to edit the changes. There are many options, this one is as good as any: Setting up and using Meld as your git difftool and mergetool - Stack Overflow[^]

A good way to reduce conflicts in the future is if all team members update their local branch AND merge as often as possible.
 
Share this answer
 
v2
Comments
columbos14927 26-Jun-18 4:42am    
Hi,
I want to explain my motivation.
When I'm merging i get hundreds of files need to be merged using git mergetool, obviously its very tedious.
So what i would like is for each file to get conflicting lines and their authors so i can mail them and have them explain how to solve the conflict manually using mergetool.
Thanks
I am really sorry, the following may not be a resolution to your situation, but it what it seems like to me:

I think this is not exactly a technical question. It seems to me like an organizational one. It is a matter of "ways-of-working". Every programmer should find and resolve his own conflicts. It is totally unacceptable to burden one person [you] with other peoples unfinished work. They must learn to use git mergetool on their own conflicts.

I realise you may be up against a hard to convince group of programmers and maybe management. But this is what you should push for. Or... to find other tasks within the organization.

To communicate a conflict as filename:linenumber is extremely inefficient, when they could graphically see it on their own screens, automatically. And it will not be enough anyway, because somebody still has to choose between the changes from two different persons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900