Introduction
Comparing two commits is an essential task in Git to understand the differences between various stages of your project. This guide explains how to compare two commits using Lazygit, which provides a user-friendly interface for this comparison.
Lazygit
-
Select the First Commit:
- Open Lazygit and navigate to the commit, branch, or reference you want to compare.
- Press
shift+w
on the selected commit. This action marks the commit for comparison.
-
Select the Second Commit:
- Navigate to and select the second commit you want to compare against the first one.
- After selecting the second commit, Lazygit displays the diff in the main view.
-
Viewing the Diff Details:
- Press
<enter>
to see a detailed view of the files involved in the diff. - This detailed view allows you to explore the specific changes between the two commits.
- Press
-
Options in Diff Menu:
- Press
shift+w
again to open the diff menu for additional options like reversing the diff direction or exiting the diff mode.
- Press
-
Exiting Diff Mode:
- You can exit the diff mode by pressing
<escape>
.
- You can exit the diff mode by pressing
Basic Terminal
To compare two commits in the terminal:
-
Use the
git diff
command with the commit hashes:- Replace
<commit-hash-1>
and<commit-hash-2>
with the actual commit hashes you want to compare.
- Replace
-
The terminal will display the differences between the two commits, similar to Lazygit but in a text format.
Comparing commits in Lazygit provides a more intuitive and visual approach, while the terminal offers a more traditional, text-based method. Both are valuable tools in a developer’s toolkit for understanding changes in a project.