How to see the Changes in a Git commit?
Last Updated :
23 May, 2024
Understanding the changes introduced in each commit is crucial for effective collaboration and version control in Git. Whether you are reviewing someone else's work or tracking your own modifications, Git provides powerful tools to inspect changes. This article will guide you through the various methods to see changes in a Git commit.
What is a git commit and how does it work?
A git commit is an action in Git that saves your changes to the local repository with a descriptive message. It captures the state of the project at that moment, creating a snapshot that you can revert to or reference later.
git commit -m "Added user authentication feature"
Explanation:
- git commit: This command tells Git to save the changes you've staged.
- -m: This option allows you to add a commit message directly from the command line.
- "Added user authentication feature": This is the commit message, which should be a brief description of the changes made. It helps you and others understand what was done in this commit.
Purpose of a Commit
- Snapshot: Each commit represents a snapshot of your project at a specific point in time.
- History: Commits form a chronological history of your project, allowing you to track changes over time.
- Revert Changes: You can revert to a previous commit if needed, which is useful for undoing mistakes.
- Collaboration: Commits help in collaborating with others by providing a clear and documented change history.
How git commit Works
Stage Your Changes
Before committing, you need to stage the changes using git add. This tells Git which changes you want to include in the next commit.
git add <file> # Stage a specific file
git add . # Stage all changes in the current directory
Create the Commit
After staging, use the git commit command with a meaningful message to save your changes.
git commit -m "Your descriptive commit message"

Viewing the changes in Git commit
To see the changes in a specific Git commit, you can use the git show command. This command displays the details of a commit, including the commit message, author, date, and the diff of changes introduced in that commit.
git show <commit-hash>
Explanation:
- git show: The command used to display the details of a specific commit.
- <commit-hash>: The unique identifier (hash) of the commit you want to inspect. You can find this hash using commands like git log.

Steps to See Changes in a Commit
Find the Commit Hash
Use the git log command to list recent commits and find the hash of the commit you're interested in.
git log
This will output a list of commits with their hashes, authors, dates, and messages. The commit hash is the long alphanumeric string at the beginning of each entry.
Show the Commit Details
Use git show followed by the commit hash to view the details of that commit. Replace 1a2b3c4d with the actual commit hash you want to inspect.
git show 1a2b3c4d
Example:
Let's say we made some changes in a project eg. added or removed code,files,folders etc. Now we made some commits with a proper message, now when we want to look at any particular commit and what changes were made in that commit we can type git log command and a log containing a set of commits will be loaded.
git log outputNow to see the changes introduced by any commit, we would run:
git show 330bd1c2848f77fd6d7939a2debf283131cd232f
Now as we hit enter the changes made in the particular commit will be shown to us.
git show outputNow here we can notice that the data that was removed is shown in red with -* and what was added is shown in green with +*
so users can visually identify the changes.
Conclusion
Git offers robust tools for inspecting changes in commits, from the command-line git show
and git diff
to advanced GUI applications. Mastering these tools allows you to track and understand code modifications effectively, facilitating better collaboration and code management in your projects.
Similar Reads
How to Change Commit Message in Git? Changing a commit message in Git can be done in a few different ways, depending on whether the commit is the most recent one or an earlier commit. Here's an article on how to change a commit message in Git, covering scenarios both before and after the commit has been pushed to a remote repository.Th
3 min read
How to Checkout a Tag in Git? When working with Git, checkout a tag is one of the basic operations. Tags are pointers that show certain points in the history of your project and usually indicate releases or some important stages. The purpose of checkout a tag is to make your working directory represent the repository as it was a
3 min read
How to Back Commit in Git? In this article, we are covering how to undo commits in Git. Sometimes, you might make mistakes or realize you need to revert changes you made in a previous commit. Luckily, Git offers a few ways to undo commits. Table of Content Approach 1: Using 'git revert'Approach 2: Using 'git reset' Approach 1
4 min read
How to Change a Git Commit Message After a Push? Accidentally deleting a branch or commit in Git can seem alarming, but Git's powerful version control capabilities often allow you to restore them with relative ease. This guide will walk you through the steps to recover a deleted branch or commit. Table of Content Restoring a Deleted BranchUsing Gi
3 min read
How To List All Commits That Changed A Specific File In Git? Git, a widely used version control system, allows developers to track changes in their codebase efficiently. One common need when working with Git is to list all commits that have modified a specific file. This can be particularly useful for tracking changes, understanding the history of a file, or
1 min read