Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the Authors and commit message for commits that cause a conflict

Tags:

git

git-commit

I have two long-running branches dev, and a far future release called future . We create fixes for the supported release by branching from the tag that exhibits the bug, fix it, and then open pull-requests to the two branches. If there is a conflict in the 'future' branch, our developers are suppose to create a new branch, resolve the conflicts, and open another PR to future.

Unfortunately, our team is large enough that plenty of these second PRs haven't been made. I need to now figure out which exact commits caused conflicts. I can do this manually by running git blame on each conflicted file, and seeing the commits on each side of the ====== line, but that doesn't actually give me enough information, and I have to manually run git blame for every conflict and every file.

Is there an easier way? Ideally, I'd want something equivalent to:

Commit X: <coworker1> I updated something.
Commit Y: <coworker2> Something fixed.
Conflicts: 
   some/file/here
   a/different/file.

for every single conflict.

Though anything that just gives me the list of conflicting commits would be useful enough to warrant the bounty.

like image 237
Daniel Avatar asked Jun 26 '15 01:06

Daniel


2 Answers

You could run git diff --diff-filter=U while merging to see diff output for all (and only) unmerged files. It's still with file content, but it's better than manually running a command for each file.

like image 103
Amber Avatar answered Sep 30 '22 21:09

Amber


You can get pretty close very easily:

git ls-files -u | cut -f2- | uniq \
| while read conflicted; do
        echo @@@ conflicted file $conflicted touched in this merge by:
        git log HEAD...MERGE_HEAD --left-right --format='    %h %aN %s' -- "$conflicted"
done

and really, it's only the right-branch (the one being merged in) commit authors you care about -- the left-branch ones have already been merged, let whoever touched what you've already got sort it out.

Add --topo-order to the log command to list the commits for each branch together.

like image 36
jthill Avatar answered Sep 30 '22 21:09

jthill