How to see commits that were merged in to a merge commit?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When a bug appears after integration, you often need to answer a precise question: which commits came through a specific merge commit. Git can provide this accurately, but only if you read parent relationships correctly and use the right revision range. A repeatable workflow prevents mistakes during incident debugging and release verification.
Step 1: Inspect Merge Parents
A merge commit has at least two parents. Parent one is usually the target branch tip before merge, and parent two is the merged branch tip.
or a shorter view:
You must confirm parent order first. If you reverse the parents later, your commit list will answer a different question.
Step 2: List Commits Brought by the Merged Side
For merge commit M, this range is the common way to list commits that came from the merged branch:
A visual version helps when graphs are complex:
Interpretation: commits reachable from M^2 that were not reachable from M^1 at merge time.
Step 3: See What Actually Landed in the Target Branch
Commit ancestry shows intent, but conflict resolution can introduce extra changes during merge. To inspect integrated patch content, compare the merge commit to its first parent.
Full patch output:
This catches edits introduced during conflict handling that may not be obvious from the source branch commit list.
Useful Variants for Common Workflows
For release notes, first-parent history is often cleaner than full graph traversal.
To inspect only merge commits:
To check whether a specific commit was on the merged side:
These commands are useful for audit trails and ticket validation.
Merge Strategy Differences
The method above assumes a real merge commit exists. Strategy matters:
- merge commit workflow: parent-based ranges work directly
- squash merge workflow: original branch commits are collapsed
- rebase-and-merge workflow: commits are rewritten and linearized
For squash merges, rely on pull request metadata, commit message conventions, and platform APIs rather than parent range math.
Practical Incident Checklist
During incidents, use a checklist so no step is skipped.
git fetch --all --pruneto avoid stale history.- Confirm merge SHA and parents.
- List merged-side commits with
M^1..M^2. - Inspect merge patch versus first parent.
- Map suspicious commits to ticket IDs.
A scripted version can reduce operator error:
Keep this in internal runbooks for on-call use.
Validate Local State Before Trusting Output
Many wrong conclusions come from stale local refs or detached worktrees. Always fetch and confirm the branch tip before analysis. If needed, run commands against explicit remote refs so output is reproducible across team members.
Reproducibility matters when multiple engineers are debugging the same production regression.
Common Pitfalls
- Reversing
M^1..M^2and listing the wrong commit set. - Assuming every merge policy creates a merge commit.
- Looking only at commit ancestry and missing conflict-resolution edits.
- Running analysis on stale local history.
- Ignoring parent order and drawing incorrect release conclusions.
Summary
- Start with merge parent inspection before any range queries.
- Use
M^1..M^2for merged-side commits in real merge-commit workflows. - Compare
M^1andMto inspect actual integrated code changes. - Adjust approach for squash and rebase-based merge strategies.
- Use a repeatable checklist or script for reliable incident and release analysis.
Related reading
- How to see the changes between two commits without commits in-between?
- How to see the changes between two commits without commits in-between?
- How to set offset committed by the consumer group using Spark's Direct Stream for Kafka?
- How to set patience as default git diff algorithm
- How to set specific Java version to Maven?
- How to show full-file Git blame in Visual Studio Code
- How to show Git log history i.e., all the related commits for a sub directory of a Git repository
- How to show the first commit by 'git log'?
.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.