View Changes Between Commits

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

Git is a popular version control system that allows developers to track changes made to their codebase over time. One of the most useful features of Git is the ability to view changes between two commits. This can be helpful when trying to understand what changes were made to a codebase, or when trying to identify the cause of a bug.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/shortlog("`Condensed Logs`") subgraph Lab Skills git/shortlog -.-> lab-12770{{"`View Changes Between Commits`"}} end

View Changes Between Commits

As a developer, you have been working on a project hosted on the https://github.com/labex-labs/git-playground repository. You have made several commits to the repository, and you want to view a summary of the changes between two specific commits. However, you are not sure how to do this using Git.

To view a summary of changes between two commits, let's say you want to view the changes between the HEAD commit and the commit with the message "Initial commit". Here's how you can do it:

  1. Open a terminal window and navigate to the directory where the git-playground repository is located:
cd git-playground
  1. Run the following command:
git shortlog 3050fc0de..HEAD

Git will display a summary of the changes between the two commits. You can use the arrow keys to navigate through the summary, and press Q to exit.

Here's an example of what the output might look like:

Hang (2):
      Added file1.txt
      Added file2.txt

In this example, Git is showing that there were two commits between the 3050fc0de commit and the HEAD commit. The first commit added file1.txt, and the second commit added file2.txt.

Summary

Viewing changes between two commits is a useful feature of Git that can help developers understand what changes were made to a codebase over time. By using the git shortlog command, developers can quickly view a summary of the changes between two specific commits.

Other Git Tutorials you may like