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:
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:
You'll see a list of commits, each with its unique SHA, author, date, and commit message.
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:
git log command uses a pager (like
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
View Specific Number of Commits: If you want to view the last 'n' number of commits, you can use:
git log -n
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! ✨