How to Check the Last Commit in Git

When working with Git, it’s often useful to view the last commit to confirm recent changes, track history, or debug an issue. Git provides simple commands to help you inspect the most recent commit on your current branch.


✅ 1. View the Last Commit Summary

To display the latest commit in a concise format:

git log -1

Output example:

commit 6a5b2c8d4f8b0a1c1d9f6a0b59a72e2ab7a2bcef
Author: Jane Doe <ja**@ex*****.com>
Date:   Tue May 28 12:34:56 2025 +0530

    Fix: updated login validation logic

📝 2. View Only the Commit Message

If you just want the message of the last commit:

git log -1 --pretty=%B

Output:

Fix: updated login validation logic

🔍 3. Show Changes Made in the Last Commit

To see the actual file changes:

git show

This shows:

  • The commit hash
  • The message
  • The diff (file changes)

You can also limit it to just the diff:

git show --name-only

💡 4. Check Last Commit on a Specific Branch

To check the last commit on, say, the main branch:

git log -1 main

Or to view a concise log of the last few commits on that branch:

git log -n 5 main

📌 Summary

TaskCommand
Show last commit (full)git log -1
Show last commit message onlygit log -1 --pretty=%B
Show last commit and diffgit show
Show files changed in last commitgit show --name-only
Show last commit on a branchgit log -1 branch-name
Sharing Is Caring:

Leave a Comment