How to perform a 3-way visual diff on git?
Asked Answered
K

2

5

I'd like to do a 3-way diff of a single file that exist in 2 different branches, that is, the last commit in each branch and also consider the common ancestor. I want to use an external tool that allows to do 3-way comparison. I was considering to use git difftool but as far as I could see it only allows comparing any 2 versions of a given file. I could use mergetool but that forces me to run git merge first so that, BASE, REMOTE and LOCAL variables are set. I don't want to run git merge. I just want to do a 3-way diff first to see the changes done on the file in both branches considering its common ancestor.

Is there an option to do what I need using difftool or mergetool? Thanks

Krol answered 10/10, 2014 at 14:3 Comment(2)
That may not be what you're after, but do you know about git config --global merge.conflictstyle diff3?Wispy
Yes, I have seen that before. However, it does not address the need I have. Thanks.Krol
C
4

One solution is the visual diffuse which can directly operate on git revisions and supports n-way views.

For example, you can open a three-way diff between different branches for a file:

diffuse -r master -r HEAD -r upstream file.txt

Crossquestion answered 22/5, 2017 at 11:33 Comment(0)
E
0

Install the 3-way diff tool you prefer, my preferred one is KDiff3.

Open for editing the GIT global configuration: git edit --global --edit

Adjust it within the tool you chosen:

[diff]  
    tool = kdiff3
[difftool]
    prompt = true
[difftool "kdiff3"]
    cmd = 'C:/Program Files/KDiff3/kdiff3.exe' \"$LOCAL\" \"$REMOTE\"
    keepBackup = false
[merge]
    tool = kdiff3   
[mergetool]
    prompt = true
[mergetool "kdiff3"]
    cmd = 'C:/Program Files/KDiff3/kdiff3.exe' \"$BASE\" \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"
    trustExitCode = true
    keepBackup = true   

To open it on a file in VS Code using right click command, I added this simple plugin: GIT diff merge tool.

Ethnarch answered 6/2, 2022 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.