Skip to content

Visual Diff and Merge Tools

โ† Back to Git


๐Ÿ‘๏ธ Visual Diff and Merge Tools

You can configure external tools like P4Merge to visualize diffs and resolve conflicts more easily than in the CLI.

1. Install Tool

Install your preferred tool (e.g., P4Merge).

2. Configure Git

Run the following commands to set P4Merge as your default merge and diff tool (adjust paths for your OS):

git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
git config --global diff.tool p4merge
git config --global difftool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
git config --global difftool.prompt false
git config --global mergetool.prompt false

3. Usage Commands

View Diff (Changes not stamped):

git difftool

Diff Working Directory vs Last Commit:

git difftool HEAD

Diff Staging Area vs Last Commit:

git diff --staged HEAD

Diff Between Two Commits:

git difftool <commit-hash-1> <commit-hash-2>
Note: Diff tool will open one file at a time. Close it to view the next one.

Diff Local vs Remote Branch:

git diff master origin/master


๐Ÿง  Quick Quiz โ€” Diff Tools

#

Which command allows you to view changes using an external visual tool?


๐Ÿ“ Want More Practice?

๐Ÿ‘‰ Start Git Advanced Quiz (20 Questions)


๐Ÿ“ฌ DevopsPilot Weekly โ€” Learn DevOps, Cloud & Gen AI the simple way.
๐Ÿ‘‰ Subscribe here