Git See my last commit
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
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:
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:
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:
Example output shape:
For changed files without the full patch:
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:
For just the hash:
For hash plus subject line:
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.
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:
Show Only Files Changed in the Last Commit
Sometimes you care more about which files changed than the patch itself.
Or:
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:
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 -1for the latest commit metadata. - Use
git show HEADwhen you want the full diff for the last commit. - Use
--oneline,--stat, or--name-onlyfor 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
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.