×

Search anything:

See changes in a specific Git commit

git

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article, we have presented how to see the code changes in a specific Git commit using "git diff" command.

Table of contents:

  1. Get commit ID
  2. See changes in a specific Git commit

In short, the command is:

git diff COMMIT~ COMMIT

Get commit ID

Note: If you want to try these commands on a specific Git repository, get a sample repository using this command:

git clone https://github.com/OpenGenus/cosmos.git
cd cosmos

For a given Git repository, using the following command you can get the list of merged commits:

git log --oneline

The output of this command will be like:

5fd954k2 (HEAD -> code-2.0, origin/master) major bug fix
4409e775 Handle case of metroid in opengenus
d6fgy990 Fix segmentation fault in Mars
559ar431 (tag: code-1.9a) Code cleanup
4faa67we Optimize travel to Saturn
...

The value at the beginning of each line (say 5fd954k2) is the commid ID. The text following the commit ID is the message title of the commit.

If you want a more detailed list of commits, use:

git log

This command is show details such as commit description, author of the commit, time of the commit and so on.

Using these commands, you can get the commit ID of the commit you want to see code changes for.

See changes in a specific Git commit

To see the code changes in a particular commit, use the following command:

git diff COMMIT~ COMMIT

Replace COMMIT with the commit ID. If we want to see the changes merged with commit ID 4409e775, the command will be:

git diff 4409e775~ 4409e775

This will display a list of changes for each modified file one by one. Keep of pressing "ENTER" to see the changes. If you wish to exit seeing the changes, press the key "Q".

With this article at OpenGenus, you must have the complete idea of how to see the code changes in a specific Git commit.

Geoffrey Ziskovin

Geoffrey Ziskovin

Geoffrey Ziskovin is an American Software Developer and Author with an experience of over 30 years. He started his career with Haskell and has interviewed over 700 candidates for Fortune 500 companies

Read More

Improved & Reviewed by:


OpenGenus Tech Review Team OpenGenus Tech Review Team
See changes in a specific Git commit
Share this