Search
Close this search box.

Git Diff

What does ‘diff’ mean in Git? A diff takes two data sets and shows you what has changed between them. Data sets can be files, commits, branches, etc. 

Let’s walk you through the concept of a diff and the benefits of using a robust diff tool, like that offered in the GitKraken Git GUI

If you’re looking for the best Diff tool on the market, look no further than the in-app Diff view offered in GitKraken.

Git Diff Between Commits 

Let’s look at an example using two commits; let’s say we want to see what has changed between Commit 1 and Commit 3. 

The diff will compare the differences between the two commits, showing what files were added, deleted, or modified. 

In this example, Commit 1 is the baseline. You may also notice how the diff looks identical to the changes from Commit 3, and that’s no mistake! The literal difference between Commit 1 and Commit 3 are the changes introduced by Commit 3. 

Git Diff Between Files

But what about the diff of each file? When examining the diff of each file, added lines of text are commonly highlighted in green or denoted with a + sign. Similarly, deleted lines of text are commonly highlighted in red or donated with a sign. 

The file diff will likely be your most useful tool for understanding what changed, and how it changed.

Why would you want to view a Git diff? 

Diffs provide useful information about your repository in a legible format, making it easier to perform the following actions: 

  • Review changes while staging. 
  • Decide whether to rebase or merge. 
  • Copy and paste code from a file. 

Giving you even more confidence in your code game. 💥

The Diff tool in GitKraken will help you make more informed decisions, allowing you to perform more advanced Git actions, like rebase, with less risk.

The Git Diff Tool in GitKraken 

Let’s see how this all works in the GitKraken Git GUI

If you click a commit in the graph, GitKraken will list all of the files changed on the right commit panel. 

Click on any file to open that file’s diff. Lines that were added to that file will show in green, and lines that were deleted will show in red. If code has been added and deleted from the same line, GitKraken will show both together. 

Hunk, Inline, and Split Diff Views 

By default, GitKraken’s Git diff tool will display in Hunk View, which displays the file changes in blocks of code, helping reduce the noise of seeing the entire file. 

However, you can toggle between Inline View, which shows the changes within the context of the entire file, or Split View, which will show you how the file appeared before and after the changes. 

View the Git Diff when Staging Files 

These options are also available when staging files. For example, try reviewing the file diffs and switching between Hunk, Inline, or Split views to make the most informed commits. 

GitKraken’s Diff tool gives you the ability to toggle between different views, so you can view your code exactly how you want to make the best decisions.

Git Diff Between Branches 

There are a few more things you can do with the Git diff in the GitKraken Git GUI

From the central graph in GitKraken, hold down the Cmd/Ctrl key to select the head commit of two branches. From here, you will have the option to view the diff between these two branches.

But what happens when you change the order of the branch selection? When you give that a try, you may see deleted files show as “added” or vice versa. That’s because direction matters when viewing a Git diff.  So keep that in mind as you click the order of branch or commit diffs. 

Customize Text Editor Preferences

GitKraken also allows the ability to easily customize preferences of the text editor available in the Git diff tool. Simply navigate to PreferencesEditor Preferences, where you can customize your Git diff tool preferences for syntax highlighting, line count, and word wrap. 

Additional Resources

Table of Contents

Make Git Easier, Safer &
More Powerful

with GitKraken

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.