Please tell me there's a better way.

I'm in a git feature branch. It was branched off of master some time ago. Then I made some commits. Later, I merged in latest master, and after that some more commits. The question is what was the SHA when I merged in latest master? How to find that out?

Here's what I did:

I'm in my feature branch and I run:


git log --merges --first-parent

It prints this out:


commit 2c010ef6e94d792f25f7309ed83a2d35e41e5051
Merge: 24b2a2513d6f e2817859ed02
Author: Peter Bengtsson <email>
Date:   Thu Feb 26 14:06:24 2026 +0000

  Merge remote-tracking branch 'origin' into name-of-my-feature-branch

The SHA that was, on master, at the time of merging, was e2817859ed02 which is the second thing the Merge: 24b2a2513d6f e2817859ed02 line.

Now, equipped with this I can go back in time git checkout e2817859ed02 and on that detached HEAD, I can do things like run (unit) tests to see if the master branch was busted at the time I merged it into my feature branch.

Comments

Jakub Narębski

First, `git log --merges --first-parent` (where `--merges` is a shortcut for `--min-parents=2`) shows all merges into your current branch. If you are interested in programmatic manipulation, use `--format=%H` to output only commit identifiers, and `-1` to show only first merge. You can then combine extracted commit identifier with `^2` suffix, which extract second parent from a commit. You can try to use `git checkout $(git log --merges --first-parent -1)^2`...

Second, after merging a branch (be it `main`, `master`, `origin` aka `origin/HEAD`, or `origin/master`) into your current branch, the state of that branch before the merge becomes current common ancestor of current branch and merged branch. You can find it with `git merge-base HEAD origin` (or whatever two branches you are interested in).

Your email will never ever be published.

Previous:
gg2 branches got 50% faster by a Promise.all February 16, 2026 JavaScript, Bun, TypeScript
Related by category:
hylite as an executable October 15, 2025 Linux
Elasticsearch memory usage December 11, 2025 Linux
How to count the number of non-blank lines with Bash September 3, 2025 Linux
gg shell completion August 13, 2025 Linux