git
version control
commit history
git commands
software development

Git See my last commit

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

If you want to see your last commit in Git, the best command depends on how much detail you need. Sometimes you only want the commit message and hash, and sometimes you want the full patch, changed files, or a compact one-line summary.

The Fastest Basic Command

To see the most recent commit on the current branch:

bash
git log -1

This shows:

  • commit hash
  • author
  • date
  • commit message

It is the simplest "show me my last commit" command.

Use git show for the Full Diff

If you also want to inspect the actual code changes introduced by the last commit:

bash
git show HEAD

HEAD points to the current commit, so git show HEAD displays:

  • commit metadata
  • full patch
  • changed lines

This is often the most useful answer when you are checking what you just committed.

Compact Views

For a short summary:

bash
git log -1 --oneline

Example output shape:

text
abc1234 Fix login timeout handling

For changed files without the full patch:

bash
git show --stat --oneline HEAD

That is a good middle ground when you want a quick reminder without reading the whole diff.

Show Only the Commit Message

If you want just the message body:

bash
git log -1 --format=%B

For just the hash:

bash
git rev-parse HEAD

For hash plus subject line:

bash
git log -1 --format="%H %s"

These are handy in scripts or release notes automation. They are also useful when you want consistent machine-readable output instead of the human-oriented default git log layout.

See the Last Commit on Another Branch

You are not limited to the current branch.

bash
git log -1 main
git show origin/main

That is useful when you want to inspect the latest commit on a remote-tracking branch without checking it out first.

If you are inspecting remote state, remember to fetch first if you need the latest remote refs:

bash
git fetch origin
git log -1 origin/main --oneline

Show Only Files Changed in the Last Commit

Sometimes you care more about which files changed than the patch itself.

bash
git diff-tree --no-commit-id --name-only -r HEAD

Or:

bash
git show --name-only --format=fuller HEAD

Both help when you are checking whether the last commit touched the files you expected.

If You Mean "The Last Commit I Authored"

Usually "my last commit" means the current HEAD commit, but if you mean the last commit authored by you anywhere in history, filter by author:

bash
git log --author="Your Name" -1

That is useful on shared branches where the latest branch tip may belong to someone else.

Common Pitfalls

The biggest mistake is assuming git log -1 always means "the last commit I personally wrote." It actually means the latest commit reachable from the current HEAD.

Another issue is using git log -1 when you really want the patch. In that case git show HEAD is the better command.

A third problem is inspecting a remote branch without fetching first and then assuming the local remote-tracking ref is current.

Summary

  • Use git log -1 for the latest commit metadata.
  • Use git show HEAD when you want the full diff for the last commit.
  • Use --oneline, --stat, or --name-only for more compact views.
  • Specify a branch or ref explicitly if you want the last commit somewhere other than current HEAD.
  • Fetch first when inspecting remote-tracking branches for up-to-date results.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.