View Git Commit Summary Excluding Merges

GitGitBeginner
Practice Now

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

Introduction

When working with Git, it's important to be able to view a summary of all the commits made to a repository. However, sometimes merge commits can clutter up the output and make it difficult to see the actual changes made. In this lab, you will learn how to view a short summary of all commits excluding merge commits.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/merge("`Merge Histories`") subgraph Lab Skills git/merge -.-> lab-12775{{"`View Git Commit Summary Excluding Merges`"}} end

View a Short Summary of Commits without Merge Commits

You have been working on a project with several other developers, and you want to see a summary of all the commits made to the repository. However, you don't want to see the merge commits, as they don't contain any actual changes to the code. How can you view a summary of all the commits excluding merge commits?

For this lab, let's use the repository from https://github.com/labex-labs/git-playground.

  1. Clone the repository, navigate to the directory and configure the identity:
git clone https://github.com/labex-labs/git-playground
cd git-playground
git config --global user.name "your-username"
git config --global user.email "your-email"
  1. Create and switch to a branch called feature1, create a file called file.txt and write feature 1 into it, add it to the staging area and commit it with the message "Add feature 1":
git checkout -b feature1
echo "Feature 1" >> file.txt
git add .
git commit -m "Add feature 1"
  1. Switch back to the master branch, merge the feature1 branch, disable the forward merge, save and exit without changing the text:
git checkout master
git merge --no-ff feature1
  1. View a short summary of all commits excluding merge commits:
git log --oneline --no-merges

This will output a list of all the commits made to the repository, excluding any merge commits. The output will look something like this:

430b986 (feature1) Add feature 1
d22f46b (origin/master, origin/HEAD) Added file2.txt
cf80005 Added file1.txt
b00b937 Initial commit

Summary

In this lab, you learned how to view a short summary of all commits excluding merge commits. This can be useful when you want to see a quick overview of all the changes made to a repository without being distracted by merge commits.

Other Git Tutorials you may like