How to View Git Branch Commits and Bonus Tips

When you're working on a project that uses Git for version control, viewing the commits on a specific branch is often helpful.

This can give you insights into the changes made, the history of the branch, and much more.

Here's a simple guide on how to view commits on a branch and a few tips:

How to

Switch to the Desired Branch (Optional): If you're not already on the branch whose commits you want to view, switch to it using:

git checkout BRANCH-NAME

View Commits: To view the commits on the branch you're currently on, use:

 git log

You'll see a list of commits, each with its unique SHA, author, date, and commit message.

Tips

For a Compact View: If you want a more concise view with just one line per commit, use:

git log --oneline

View Commits with Graph: To see a graphical representation of the commits along with branch/merge points, use:

git log --oneline --graph

Filter Commits: If you want to view commits from a specific author, use:

git log --author="Author Name"

Paging Through Commits: The git log command uses a pager (like less or more on most systems) to display one screenful of commits at a time. You can navigate using the arrow keys and quit the log view by pressing q.

View Specific Number of Commits: If you want to view the last 'n' number of commits, you can use:

git log -n

Replace n with the number of commits you wish to see.

View Commits Between Two Dates:

To filter commits between specific dates, use:

git log --after="YYYY-MM-DD" --before="YYYY-MM-DD"

Happy coding! ✨

Git
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.