check git diff between commits

How to Check Git Diff Between Commits

Git diff command displays difference between commits. There are several ways to check git diff between commits. In this article, we will learn them one by one.


How to Check Git Diff Between Commits

Here are the different ways to check git diff between commits.

git diff oldCommit..newCommit
OR
git diff oldCommit newCommit

For example, if you want to find difference between git commits a73ud and b45gd

git diff a73ud..b45gd
OR
git diff a73ud b45gd

If you want to view only the files names in which changes have taken place, add –name-only option.

git diff a73ud b45gd --name-only

If you only want to see a specific file’s (e.g. data.txt) diffs in two commits, you can add — and mention the filename.

git diff a73ud b45gd -- data.txt

Here is the command to check difference between working and staging area.

% git diff

Here is the command to check difference between staging area and latest commit.

% git diff --staged

Here is the command to check difference between working copy and commit ae7ud

% git diff ae7ud

Here is the command to check difference between ae7ud and latest commit.

% git diff 4ac0a6733 HEAD

In this article, we have seen several ways to check difference between two commits in git. You can customize them as per your requirements.

Also read:

How to Checkout Specific Commit in Git
How to Take Screenshot of Div in JS
How to Create Incremental Backup in Linux
How to Improve Ubuntu Speed & Performance
How to Embed PDF in HTML

Leave a Reply

Your email address will not be published.